4 Replies Latest reply on Dec 29, 2010 12:02 PM by charles_newman-GG8xMm

    Audio but no Video when using MediaPlayer object

    track180

      I'm attempting to get a simple OSMF Player to play an FLV using the MediaPlayer object. Audio is played, but no video is shown.

       

      I've adapted the example code from the AS3 Reference docs for MediaPlayer. http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/org/osmf/media/MediaPla yer.html (MediaPlayerExample.as) I've altered the code slightly to play an FLV in accordance with the Plugin developer documentation (OSMF_plugin_dev_guide.pdf - p.3 provides example player code where URLResource & MediaFactory are used together to load MediaPlayer with an FLV)

       

      package
      {
          import flash.display.Sprite;
           import org.osmf.media.DefaultMediaFactory;
           import org.osmf.media.MediaFactory;
          
          import org.osmf.containers.MediaContainer;
          import org.osmf.elements.AudioElement;
          import org.osmf.events.TimeEvent;
          import org.osmf.media.MediaPlayer;
          import org.osmf.media.URLResource;
          
          public class MediaPlayerExample extends Sprite
          {
              private var mediaPlayer:MediaPlayer;
              
              public function MediaPlayerExample()
              {            
                  super();
                              
                  mediaPlayer = new MediaPlayer();
                  var factory:MediaFactory = new DefaultMediaFactory;
                  var resource:URLResource = new URLResource("http://mediapm.edgesuite.net/strobe/content/test/AFaerysTale_sylviaApostol_640_500_short.flv");
                                          
                  mediaPlayer.volume = .5;
                  mediaPlayer.loop = true;
                  mediaPlayer.addEventListener(TimeEvent.CURRENT_TIME_CHANGE, onTimeUpdated);        
                  mediaPlayer.addEventListener(TimeEvent.DURATION_CHANGE, onTimeUpdated);
                  mediaPlayer.autoPlay = true;
                  mediaPlayer.media = factory.createMediaElement(resource);    
              }
              
              private function onTimeUpdated(event:TimeEvent):void
              {
                  trace('time: ' + mediaPlayer.currentTime + ' duration: ' + mediaPlayer.duration);
              }
          }
      }

      This code compiles and runs, but no video is shown - only audio. Why won't this play video?

       

      Any thoughts are greatly appreciated.

        • 1. Re: Audio but no Video when using MediaPlayer object
          Nicolas Siver Level 1

          And where MediaPlayerSprite or MediaContainer at least?

          • 2. Re: Audio but no Video when using MediaPlayer object
            Nicolas Siver Level 1

            Also Default Factory adds unnecessary kb to application. If you need simple progressive player, you should simply create VideoElement with URLResource.

            • 3. Re: Audio but no Video when using MediaPlayer object
              track180 Level 1

              For legacy reasons, we need to support MediaPlayer, so MediaPlayerSprite isn't an option. (even though simple replacement of MediaPlayer w/ MediaPlayerSprite does play the video in this example)

               

              Hmm. Passing a VideoElement doesn't seem to play audio or video:

               

               

               

              package

              {

                  import flash.display.Sprite;

                   import org.osmf.elements.VideoElement;

                   import org.osmf.media.DefaultMediaFactory;

                   import org.osmf.media.MediaFactory;

               

                  import org.osmf.containers.MediaContainer;

                  import org.osmf.elements.AudioElement;

                  import org.osmf.events.TimeEvent;

                  import org.osmf.media.MediaPlayer;

                  import org.osmf.media.URLResource;

               

                  public class MediaPlayerExample extends Sprite

                  {

                      private var mediaPlayer:MediaPlayer;

               

                      public function MediaPlayerExample()

                      {           

                          super();

               

                          mediaPlayer = new MediaPlayer();

                          var factory:MediaFactory = new DefaultMediaFactory;

                          var resource:URLResource = new URLResource("http://mediapm.edgesuite.net/strobe/content/test/AFaerysTale_sylviaApostol_640_500_short.f lv");

                             var vid:VideoElement = new VideoElement();

                             

                             vid.resource = new URLResource("http://mediapm.edgesuite.net/strobe/content/test/AFaerysTale_sylviaApostol_640_500_short.f lv");

               

                          mediaPlayer.volume = .5;

                          mediaPlayer.loop = true;

                          mediaPlayer.addEventListener(TimeEvent.CURRENT_TIME_CHANGE, onTimeUpdated);       

                          mediaPlayer.addEventListener(TimeEvent.DURATION_CHANGE, onTimeUpdated);

                          mediaPlayer.autoPlay = true;

                          //mediaPlayer.media = factory.createMediaElement(resource);   

                             mediaPlayer.media = vid;   

                      }

               

                      private function onTimeUpdated(event:TimeEvent):void

                      {

                          trace('time: ' + mediaPlayer.currentTime + ' duration: ' + mediaPlayer.duration);

                      }

                  }

              }

               

              • 4. Re: Audio but no Video when using MediaPlayer object
                charles_newman-GG8xMm Level 1

                The MediaPlayer class is a controller class, it has no UI. You need to use MediaPlayerSprite or roll your own.

                 

                Example:

                 

                private var mediaPlayerSprite:MediaPlayerSprite;

                 

                 

                private static const VIDEO:String = "http://www.example.com/myvideo.flv";

                 

                 

                public function Sample()

                {

                 

                mediaPlayerSprite = new MediaPlayerSprite();

                addChild(mediaPlayerSprite);

                 

                var resource:URLResource = new URLResource(VIDEO);

                mediaPlayerSprite.media = mediaPlayerSprite.mediaFactory.createMediaElement(resource);

                }

                 

                 

                 

                Thanks,
                - charles