3 Replies Latest reply on Mar 31, 2010 9:51 AM by bringrags

    Difficulty pulling metadata from video.

    WebAppEngineer Level 1

      I am working with the OSMFPlayer sample and I have tried two different ways to pulling the metadata from the video and both have failed.

       

      First I tried:

       

      mediaElement = createMediaElement(url);

                

      if (mediaElement)

      {

        

          var loadTrait:LoadTrait = mediaElement.getTrait(MediaTraitType.LOAD) as LoadTrait;

          loadTrait.addEventListener(LoadEvent.LOAD_STATE_CHANGE, onLoadStateChange);

      }

       

      private function onLoadStateChange(event:LoadEvent):void

      {

          switch (event.loadState)

          {

              case LoadState.READY:

                  var videoElement:VideoElement = VideoElement(element);

                  videoElement.client.addHandler(NetStreamCodes.ON_META_DATA, onMetadata);

                  break;                  

          }

      }

       

      Second I tried:

       

      private function setupMediaFactory():void

      {

          factory = new DefaultMediaFactory();

          factory.addEventListener(MediaFactoryEvent.MEDIA_ELEMENT_CREATE,onMediaElementC reation);

      }

       

       

       

      private function onMediaElementCreation(e:MediaFactoryEvent):void

      {

          if (e.mediaElement is VideoElement)

          {

              var videoElement:VideoElement = e.mediaElement as VideoElement;

              videoElement.client.addHandler(NetStreamCodes.ON_META_DATA, onMetadata);

          }

      }

       

      That am I doing wrong here?

        • 1. Re: Difficulty pulling metadata from video.
          bringrags Level 4

          The first approach should work (provided that you call loadTrait.load()).  The second approach will also only work if you load the VideoElement.

          • 2. Re: Difficulty pulling metadata from video.
            WebAppEngineer Level 1

            I have tryied adding loadTrait.load(); in severial places that seem to make sense to me and still the onLoadStateChange method never gets called.

            • 3. Re: Difficulty pulling metadata from video.
              bringrags Level 4

              Here's an example that worked for me.  Note that I'm listening for the MediaPlayerStateChange's READY event rather than a loadStateChangeEvent (although the latter should work equally well):

               

              public class HelloWorld extends Sprite
                  {
                      public function HelloWorld()
                      {
                          // Create the container class that displays the media.
                           var container:MediaContainer = new MediaContainer();
                          addChild(container);

               

                          // Create the resource to play.
                          var resource:URLResource = new URLResource("http://mediapm.edgesuite.net/strobe/content/test/AFaerysTale_sylviaApostol_640_500_short.f lv");
                         
                          // Create the MediaElement and add it to our container class.
                          videoElement = new VideoElement(resource);
                          container.addMediaElement(videoElement);
                         
                          // Set the MediaElement on a MediaPlayer.  Because autoPlay
                          // defaults to true, playback begins immediately.
                          mediaPlayer = new MediaPlayer();
                          mediaPlayer.addEventListener(MediaPlayerStateChangeEvent.MEDIA_PLAYER_STATE_CHANGE, onStateChange);
                          mediaPlayer.media = videoElement;
                      }
                     
                      private function onStateChange(event:MediaPlayerStateChangeEvent):void
                      {
                          if (event.state == MediaPlayerState.READY)
                          {
                              videoElement.client.addHandler("onMetaData", onMetadata);
                          }
                      }
                     
                      private function onMetadata(info:Object):void
                      {
                          for (var value:Object in info)
                          {
                              trace(value + " = " + info[value]);
                          }
                      }
                     
                      private var mediaPlayer:MediaPlayer;
                      private var videoElement:VideoElement;
                  }