7 Replies Latest reply on Jun 25, 2010 2:52 PM by Amit Kumar

    How to get NetStream messages and how to get Max bandwidth and FPS using osmf player apis?

    Amit Kumar Adobe Employee

      Hi

       

      Can anybody tell how to get NetStream messages like NetStream.Buffer.Full, NetStream.Buffer.Empty etc and how to get Max bandwidth and FPS using osmf player apis?

       

      Regards,

      Amit

        • 1. Re: How to get NetStream messages and how to get Max bandwidth and FPS using osmf player apis?
          bringrags Level 4

          If the question is how to access the NetStream, see this somewhat related thread which explains how to hook into the NetLoader workflow to get access to the NetStream:

           

          http://forums.adobe.com/message/2725207#2725207

          • 2. Re: How to get NetStream messages and how to get Max bandwidth and FPS using osmf player apis?
            Amit Kumar Adobe Employee

            Here is my code and I have the netmocker package but how do I use TracingNetLoader class to get NetStream status messages in my DynamicStreaming class. Please also tell how to get Max bandwidth and FPS using osmf player.

             

            package
            {
            import flash.display.Sprite;
            import flash.display.StageAlign;
            import flash.display.StageScaleMode;

            import org.osmf.media.MediaPlayer;
            import org.osmf.containers.MediaContainer;
            import org.osmf.media.URLResource;
            import org.osmf.net.NetLoader;
            import org.osmf.elements.VideoElement;
            import org.osmf.utils.URL;
            import org.osmf.net.DynamicStreamingResource ;
            import org.osmf.net.DynamicStreamingItem ;
            import org.osmf.net.StreamType;

            import org.osmf.traits.*
            import org.osmf.events.*;
            import flash.net.NetStream;
            import flash.net.NetConnection;


              public class DynamicStreaming extends Sprite
              {

              private const RTMP_URL : String = "rtmp://10.10.10.10/vod/" ;

               public function DynamicStreaming()
               {
               super();
                       
               stage.scaleMode = StageScaleMode.NO_SCALE;
               stage.align = StageAlign.TOP_LEFT;

               mediaPlayer = new MediaPlayer ( ) ;
               container = new MediaContainer ( ) ;
               addChild ( container ) ;
               //set the player to play videos only once by default
               mediaPlayer.autoRewind=false;
              
               /*var resource : DynamicStreamingResource = new DynamicStreamingResource ( RTMP_URL, StreamType.DVR) ;
               var vector : Vector.<DynamicStreamingItem> = new Vector.<DynamicStreamingItem> ( 3 ) ;
               vector [ 0 ] = new DynamicStreamingItem ( "mp4:sample1.f4v" , 2000 ) ;
               vector [ 1 ] = new DynamicStreamingItem ( "mp4:sample2.f4v" , 1000 ) ;
               vector [ 2 ] = new DynamicStreamingItem ( "mp4:sample3.f4v" , 800 ) ;*/
              
               resource = new DynamicStreamingResource ( RTMP_URL, null) ;
               var vector : Vector.<DynamicStreamingItem> = new Vector.<DynamicStreamingItem> ( 3 ) ;
               vector [ 0 ] = new DynamicStreamingItem ( "mp4:sample1_1500kbps.f4v" , 1500 ) ;
               vector [ 1 ] = new DynamicStreamingItem ( "mp4:sample1_150kbps.f4v" , 150 ) ;
               vector [ 2 ] = new DynamicStreamingItem ( "mp4:sample1_500kbps.f4v" , 500 ) ;
              
               resource.streamItems = vector ;
               videoElement = new VideoElement( resource ) ;
               videoElement.addEventListener(MediaElementEvent.TRAIT_ADD, onTraitAdd);
               mediaPlayer.media = videoElement ;
               container.addMediaElement ( videoElement ) ;
              }
             
              public function onTraitAdd(event:MediaElementEvent):void
              {
               switch (event.traitType)
               {
                case MediaTraitType.DYNAMIC_STREAM:
                 _dsTrait = mediaPlayer.media.getTrait(MediaTraitType.DYNAMIC_STREAM) as DynamicStreamTrait;
                 if (_dsTrait != null)
                 {
                  _dsTrait.addEventListener(DynamicStreamEvent.SWITCHING_CHANGE, onSwitchingChange);
                 }
                 break;
                
                case MediaTraitType.DISPLAY_OBJECT:
                 _displayObjectTrait = mediaPlayer.media.getTrait(MediaTraitType.DISPLAY_OBJECT) as DisplayObjectTrait;     
                 break;
                
                case MediaTraitType.BUFFER:
                 _bufferTrait = mediaPlayer.media.getTrait(MediaTraitType.BUFFER) as BufferTrait;
                 break;
                
                case MediaTraitType.DVR:
                 _dvrTrait = mediaPlayer.media.getTrait(MediaTraitType.DVR) as DVRTrait;     
                 break;
                
                case MediaTraitType.LOAD:
                 _loadTrait = mediaPlayer.media.getTrait(MediaTraitType.LOAD) as LoadTrait;     
                 break;
                
                case MediaTraitType.SEEK:
                 _seekTrait = mediaPlayer.media.getTrait(MediaTraitType.SEEK) as SeekTrait;
                 break;
               }
              }
             
              private function onSwitchingChange(event:DynamicStreamEvent):void
              {
               var msg:String = "Switching change "
               var showCurrentIndex:Boolean = false;
              
               if (event.switching)
               {
                msg += "REQUESTED";
               }
               else
               {
                msg += "COMPLETE";
                showCurrentIndex = true;
               }
              
               trace("Info: " + msg);
              
               if (showCurrentIndex)
               {
                var streamMsg:String = "Current streaming profile index: " + _dsTrait.currentIndex + " of " + _dsTrait.maxAllowedIndex;
                trace("Info: " + streamMsg);
               
                streamMsg = "Current bitrate = " + _dsTrait.getBitrateForIndex(_dsTrait.currentIndex) + "kbps";
                trace("Info: " + streamMsg);
               }
              }
             
              private var mediaPlayer:MediaPlayer;
              private var container:MediaContainer;
              private var videoElement : VideoElement;
              private var _dsTrait:DynamicStreamTrait;
              private var _displayObjectTrait:DisplayObjectTrait;
              private var _bufferTrait:BufferTrait;
              private var _dvrTrait:DVRTrait;
              private var _loadTrait:LoadTrait;
              private var _seekTrait:SeekTrait;
              private var _tracingNetLoader:TracingNetLoader;
              private var resource:DynamicStreamingResource;
              private var netstream:NetStream;
                }

            }

            import org.osmf.media.URLResource;
            import flash.events.NetStatusEvent;
            import flash.net.NetConnection;
            import flash.net.NetStream;

            import org.osmf.net.NetClient;
            import org.osmf.net.NetLoader;
            import org.osmf.netmocker.DefaultNetConnectionFactory;

            class TracingNetLoader extends NetLoader
            {
            private var ns:NetStream;
            public function TracingNetLoader()
            {
              super(new DefaultNetConnectionFactory());
            }
              
            override protected function createNetStream(connection:NetConnection, resource:URLResource):NetStream
            {
              ns = new NetStream(connection);
              ns.client = new NetClient();
              ns.addEventListener(NetStatusEvent.NET_STATUS, onNetStreamNetStatusEvent);
              return ns;
            }

            private function onNetStreamNetStatusEvent(event:NetStatusEvent):void
            {
              trace("NetStream: " + event.info.code + ": " + event.info.level);
            }
            }

             

            Regards,

            Amit

            • 3. Re: How to get NetStream messages and how to get Max bandwidth and FPS using osmf player apis?
              bringrags Level 4

              To use TracingNetLoader, try this:

               

              videoElement = new VideoElement(resource, new TracingNetLoader());

               

              To get the max bandwidth you can acces the NetStream.info.maxBytesPerSecond property (in TracingNetLoader.createNetStream).

               

              For FPS properties, you can access VideoElement.currentFPS.

              • 4. Re: How to get NetStream messages and how to get Max bandwidth and FPS using osmf player apis?
                Amit Kumar Adobe Employee

                Hi Brian,

                 

                Thanks for replying but its still not working. Initially without passing "new TracingNetLoader()" it was streaming videos dynamically based on bandwidth and as soon as I pass the this second parameter I get following error in traces:

                 

                NetStream: NetStream.Play.StreamNotFound: error

                 

                Thanks,

                Amit

                • 5. Re: How to get NetStream messages and how to get Max bandwidth and FPS using osmf player apis?
                  bringrags Level 4

                  Ahh, you would need to have TracingNetLoader extend RTMPDynamicStreamingNetLoader rather than NetLoader.  The former supports MBR, the latter does not.

                  • 7. Re: How to get NetStream messages and how to get Max bandwidth and FPS using osmf player apis?
                    Amit Kumar Adobe Employee

                    Hi Brian,

                     

                    Thanks a lot for your help. And I am finally able to get all status messages and information. I just called super() inside TracingNetLoader() without any parameter and it worked. And for other info I did the below and its working now.

                     

                    trace("Current FPS : " + ns.currentFPS);
                    trace("CurrentBytesPerSecond : " + ns.info.currentBytesPerSecond);
                    trace("MaxBytesPerSecond : " + ns.info.maxBytesPerSecond);

                     

                    Thanks,

                    Amit