#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2006
    Posts
    660
    Rep Power
    31

    Audio playing complete(streamed), then do an action - AS3


    I am trying to get my streaming audio to do an action once the audio has finished streaming. I can not seem to get it to work.

    Code:
    btn.addEventListener(MouseEvent.CLICK, btnClick);
    
    var sc:SoundChannel = new SoundChannel();
    var s:Sound = new Sound();
    var soundReq:URLRequest = new URLRequest("http://sample.com/audio.mp3");
    s.load(soundReq);
    
    function btnClick(e:MouseEvent):void
    {
    		sc = s.play();
    }
    
    
    // Listen for when audio is finished streaming
    s.addEventListener(Event.COMPLETE, finished);
    
    function finished (e:Event):void{
    	trace("finished streaming audio");
    }
    I have tried conditions bytesLoaded == bytesTotal but that doesnt seem to work either. I only want the finish function to work when the audio has finished playing and not when it finished buffering or loading it.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2006
    Posts
    660
    Rep Power
    31
    Solution found:
    Code:
    btn.addEventListener(MouseEvent.CLICK, btnClick);
    
    var sc:SoundChannel = new SoundChannel();
    var s:Sound = new Sound();
    var soundReq:URLRequest = new URLRequest("http://sample.com/audio.mp3");
    s.load(soundReq);
    
    function btnClick(e:MouseEvent):void
    {
    sc = s.play();
    // Listen for when audio is finished streaming
    sc.addEventListener(Event.SOUND_COMPLETE, finished);
    }
    
    function finished (e:Event):void{
    	trace("finished streaming audio");
    }

IMN logo majestic logo threadwatch logo seochat tools logo