1 Reply Latest reply on May 26, 2010 9:02 AM by bringrags

    Seeking an audioElement inside a composition

    st-f Level 1

      It seems that AudioElement is not working well when used inside a composition (parallelElement).

       

      AudioElement does not dispatch CURRENT_TIME_CHANGE after SEEKING_CHANGE is dispatched for the first time. Change useVideo to true, you will then see CURRENT_TIME_CHANGE dispatched even after seeking.

       

      It's probably related to that bug: https://bugs.adobe.com/jira/browse/FM-917. Seeking doesn't seems to work right with SerialElement.

       

      Here's a sample code:

       

      package
      {
           import com.bit101.components.PushButton;
           
           import flash.display.Sprite;
           import flash.events.Event;
           import flash.events.MouseEvent;
           
           import org.osmf.containers.MediaContainer;
           import org.osmf.elements.AudioElement;
           import org.osmf.elements.VideoElement;
           import org.osmf.elements.ParallelElement;
           import org.osmf.elements.SerialElement;
           import org.osmf.elements.SoundLoader;
           import org.osmf.events.SeekEvent;
           import org.osmf.events.TimeEvent;
           import org.osmf.layout.LayoutUtils;
           import org.osmf.media.MediaElement;
           import org.osmf.media.MediaPlayer;
           import org.osmf.media.URLResource;
           import org.osmf.net.NetLoader;
           
           /**
            *  THIS IS A SIMPLE TEST OF PLAYING AN AUDIO FILE IN A PARALLEL ELEMENT, 
            *  OR INSIDE A PARALLEL ELEMENT INSIDE A SERIAL ELEMENT.
            *  THIS BEHAVIOR DOESNT OCCUR ON PLAYING AN AUDIO FILE DIRECTLY.
            */     
           
           [SWF(backgroundColor="0x000000", frameRate="25", width="915", height="360")]
           public class TestAudioBug extends Sprite
           {
                
                private var useDefaultDuration:Number = 20; // -1 for FALSE
                private var useSerialElement:Boolean = false;
                private var useVideo:Boolean = false;
                private var seekvalue:Number = 5;
                
                private var btn1:PushButton;
                private var videoelement:VideoElement;
                private var audioelement:AudioElement;
                private var pElement:ParallelElement;
                private var sElement:SerialElement;
                private var mediaContainer:MediaContainer;
                private var mediaPlayer:MediaPlayer;
                private var audioURL:String = "http://localhost:8888/videotest/alloyMental.mp3";
                private var videoURL:String = "http://localhost:8888/videotest/Milan_IT_640x360.flv";
                
                public function TestAudioBug()
                {
                     this.addEventListener(Event.ADDED_TO_STAGE, init);
                }
                
                private function init(e:Event):void
                {
                     createPlayer();
                     createNav();
                     createParallel();
                     startPlayback();
                }
                
                private function createPlayer():void
                {
                     mediaContainer = new MediaContainer();
                     addChild(mediaContainer); 
                     mediaPlayer = new MediaPlayer();
                     mediaPlayer.addEventListener(SeekEvent.SEEKING_CHANGE, onSeekChange);
                     mediaPlayer.addEventListener(TimeEvent.CURRENT_TIME_CHANGE, onTimeChange);
                }     
                
                private function createNav():void
                {
                     btn1 = new PushButton();
                     btn1.label = "seek";
                     btn1.addEventListener(MouseEvent.CLICK, seek);
                     addChild(btn1);
                }
                
                private function createParallel():void
                {
                     audioelement = new AudioElement(new URLResource(audioURL));
                     videoelement = new VideoElement(new URLResource(videoURL));
                     if(useDefaultDuration > -1) 
                     {
                          audioelement.defaultDuration = useDefaultDuration;
                          trace("\n\n\n\audioelement HAS A DEFAULT DURATION");
                     }
                     else
                     {
                          trace("\n\n\n\audioelement DOES NOT HAVE A DEFAULT DURATION");
                     }
                     pElement = new ParallelElement();
                     if(useVideo)
                     {
                          pElement.addChild(videoelement);
                     }
                     else
                     {
                          pElement.addChild(audioelement);
                     }
                }
                
                private function startPlayback():void
                {
                     if(useSerialElement)
                     {
                          trace("playback inside a SERIAL element\n\n\n");
                          sElement = new SerialElement();
                          sElement.addChild(pElement);
                          mediaPlayer.media = sElement;
                          mediaContainer.addMediaElement( sElement ); 
                     }
                     else
                     {
                          trace("playback inside a PARALLEL element\n\n\n");
                          mediaPlayer.media = pElement;
                          mediaContainer.addMediaElement( pElement ); 
                     }
                }
                
                private function seek(e:MouseEvent):void
                {
                     trace("seek(), canSeek? "+mediaPlayer.canSeek+" seeking? "+mediaPlayer.seeking+" is temporal? "+mediaPlayer.temporal+" to "+seekvalue+":00");
                     mediaPlayer.seek(seekvalue);
                }
                
                private function onTimeChange(e:TimeEvent):void
                {
                     trace("onTimeChange: "+e.time);
                }
                
                private function onSeekChange(e:SeekEvent):void
                {
                     trace("onSeekChange: still seeking? "+e.seeking);
                }
                
           }
      }