3 Replies Latest reply on Jan 11, 2010 12:46 PM by RyanOConnell

    OSMF and NetStreamCodes question.

    chaimsaj Level 1

      Hi All.

      Last time, Charles really helped me out with reding OnMetadata. Now, a similar question. If I want to listen to NetStreamCodes events, how I make it?

      I put a listener if the mediaElement is loaded, and then onMetadata works, but listeners to NetStreamCodes don't work.

      Has someone some example of this working?What I'm doing wrong? Where I'm supposeed to listen it?

      My idea is listen for StreamNotFound and for Play.Start

      Thanks

        • 1. Re: OSMF and NetStreamCodes question.
          RyanOConnell Level 2

          Hi Chaimsaj,

           

          Good question, both Play.start and the StreamNot found are both bubbled up through the OSMF typed APIs.  When a video begins playing, it's PlayTrait's playState property is PlayState.PLAYING.  You can listen for the playstate on the media player as well, which is much friendlier than the trait syntax.  When it encounters SteamNotFound, this is bubbled up as a MediaErrorEvent.

           

          mediaPlayer.addEventListener(PlayEvent.PLAY_STATE_CHANGE, onPlayState)

           

          function onPlayState(event: PlayEvent):void

          {

              switch(event.playState )

               {

                    case PlayState.PLAYING:

                    //Process play start

                         break;

           

           

                    case PlayState.PAUSED:

           

                    //Process pause

                         break;

           

                    case  PlayState.STOPPED:

                    //Process play stop

                         break;

               }

          }

           

          The StreamNotFound will be surfaced as a MediaErrorEvent.MEDIA_ERROR from the VideoElement.  If you do happen to have some custom logic that need the metadata, use this line, once the media has loaded to attach a handler:

           

           

          videoElement.addEventListener(MediaErrorEvent.MEDIA_ERROR, onError);

          function onMediaError(event:MediaErrorEvent):void

          {

               //Process media error here

          }

           

           

          And if you need something more, such as custom server callbacks, you can still get to the stream.client.  Here is the code:

           

          NetClient(videoElement.stream.client).addHandler(NetStreamCodes.ON_META_DATA, onMetaData);

          function onMetaData(value:Object):void

          {

             ....Process Metadata Here...

          }

          • 2. Re: OSMF and NetStreamCodes question.
            chaimsaj Level 1

            Worked as a charm..Thanks a lot. Now, Same area, how can I listen for netConnection events, as connection success, failed, etc?

            Thanks again..

            • 3. Re: OSMF and NetStreamCodes question.
              RyanOConnell Level 2

              Lower level events, such as NetConnection success & fail are abstracted up through the framework via the Load events.  Load events are triggered as state changes on the LoadTrait.   The MediaPLayer doesn't fire LoadEvents, but abstracts them further as MediaPlayerStateChangeEvent.MEDIA_PLAYER_STATE_CHANGE events.  Successful NetConnection is indicated by MediaPlayerState.READY.  A connection error is indicated by the MediaPlayerState.PLAYBACK_ERROR.