14 Replies Latest reply on Feb 22, 2012 8:14 PM by ReDrUmNZ

    Seeking within client buffer in OSMF player flushes the client buffer

    Amit Kumar Adobe Employee

      Hi,

       

      In one of the skin for OSMF player I saw that when we seek then loaded bar and current bar both becomes equal to seek point and it again starts loading from seek point though loaded bar was greater than current bar initially.

      In other words I can say when we perform seek operation then bufferLength becomes 0 and start buffering once again from the seek point but if we are seeking within the client buffer why should it make bufferLength 0 and flush older data which was already buffered.

      Anyone has idea on this issue.

       

      Regards,

      Amit

        • 1. Re: Seeking within client buffer in OSMF player flushes the client buffer
          weizhangstrobe Level 2

          What you described is the standard behavior of FMS3. But since FMS 3.53, it has supported in buffer seek. The default for in buffer seek is false, so you must explicitly turn it on. OSMF is in the process of adding that feature to our core framework.

           

          -Wei Zhang

          Senior Computer Scientist

          Adobe Systems, Inc.

          weizhang@adobe.com

          • 2. Re: Seeking within client buffer in OSMF player flushes the client buffer
            Amit Kumar Adobe Employee

            Can you provide some hint on how can I enable it in the OSMF Framework?

             

            Regards,

            Amit

            • 3. Re: Seeking within client buffer in OSMF player flushes the client buffer
              weizhangstrobe Level 2

              Take a look at ActionScript reference manual for Flash Player 10.1.

               

              The NetStream class has two relevant properties: inBufferSeek and backBufferLength. The reference is quite clear on the usage of these two properties.

               

               

              -Wei Zhang

              Senior Computer Scientist

              Adobe Systems, Inc.

              weizhang@adobe.com

              • 4. Re: Seeking within client buffer in OSMF player flushes the client buffer
                Amit Kumar Adobe Employee

                Thanks for your prompt reply. I have used these properties in normal video player but I wanted to know how to access NetStream in OSMF to apply this property. Can you point roughly where in code I can access this?

                 

                Regards,

                Amit

                • 5. Re: Seeking within client buffer in OSMF player flushes the client buffer
                  weizhangstrobe Level 2

                  I see what you mean. Here is what you can do.

                   

                  Assume in your player application you have access an instance of MediaPlayer. Then, you can register to listen to one of the capability change event of the MediaPlayer. Upon receiving the dispatch of the event, you can retrieve the load trait which gives you access to the net stream object and you can go from there.

                   

                   

                  -Wei Zhang

                  Senior Computer Scientist

                  Adobe Systems, Inc.

                  weizhang@adobe.com

                  • 6. Re: Seeking within client buffer in OSMF player flushes the client buffer
                    Amit Kumar Adobe Employee

                    _loadTrait = mediaPlayer.media.getTrait(MediaTraitType.LOAD) as LoadTrait;

                    if (_loadTrait != null)

                    {
                          _loadTrait.addEventListener(<events>, eventhandler);
                    }

                     

                    Events:

                    1. activate

                    2. bytesTotalChange

                    3. deactivate

                    4. loadStateChange

                     

                    Which event to use? Or am I wrong? Can you be a little ellaborate on the event part which needs to be registered?

                    • 7. Re: Seeking within client buffer in OSMF player flushes the client buffer
                      Amit Kumar Adobe Employee

                      Am I doing it right?

                       

                      var

                       

                      loadTrait:NetStreamLoadTrait = mediaPlayer.media.getTrait(MediaTraitType.LOAD) as NetStreamLoadTrait;

                       

                      if (loadTrait && loadTrait.netStream)

                      {

                      loadTrait.netStream.inBufferSeek = true;

                      }

                       

                      Regards,

                      Amit

                      • 8. Re: Seeking within client buffer in OSMF player flushes the client buffer
                        weizhangstrobe Level 2

                        Yes, this is correct. The event you want to listen to may be MediaPlayerCapabilityChangeEvent.canPlayChange.

                         

                        -Wei Zhang

                        Senior Computer Scientist

                        Adobe Systems, Inc.

                        weizhang@adobe.com

                        • 9. Re: Seeking within client buffer in OSMF player flushes the client buffer
                          Amit Kumar Adobe Employee

                          Thanks a lot. I was able to do it and Its working in the way I wanted.

                           

                          Regards,

                          Amit

                          • 10. Re: Seeking within client buffer in OSMF player flushes the client buffer
                            ReDrUmNZ Level 1

                            Hi Amit & Wei,

                             

                            How did you get this working? I keep getting null for the NetStreamLoadTrait which means I can't access the NetStream. Any ideas what I'm doing wrong? I'm using OSMF 1.6.1.

                             

                            var player:MediaPlayer = new MediaPlayer();

                             

                            player.addEventListener(MediaPlayerCapabilityChangeEvent.CAN_LOAD_CHANGE, capabilityHandler);

                             

                            function capabilityHandler(event:MediaPlayerCapabilityChangeEvent):void

                            {

                                 if(event.type == MediaPlayerCapabilityChangeEvent.CAN_PLAY_CHANGE)

                                 {

                                      var mediaElement:MediaElement = player.media;

                                      if (mediaElement.hasTrait(MediaTraitType.LOAD))

                                      {

                                           var loadTrait:NetStreamLoadTrait = mediaElement.getTrait(MediaTraitType.LOAD) as NetStreamLoadTrait; // ALWAYS NULL

                                          

                                           // This fails because loadTrait is always null. It's possible to return a CompositeLoadTrait however this doesn't grant me access to the netStream?

                                           if (loadTrait && loadTrait.netStream)

                                           {

                                                // Do stuff...

                                           }

                                      }

                                 }

                            }

                             

                            Cheers,

                             

                            Tim

                            • 11. Re: Seeking within client buffer in OSMF player flushes the client buffer
                              Silviu Vergoti Adobe Employee

                              Hi Tim,

                               

                              you should wait for the media to finish loading:

                               

                              mediaElement.addEventListener(MediaElementEvent.TRAIT_ADD, onTraitAdd);

                               

                               

                                private function onTraitAdd(event:MediaElementEvent):void

                                  {

                                    trace(" [add]", event.toString()); 

                                    if (event.traitType == MediaTraitType.LOAD)

                                    {

                                     

                                      if (mediaElement.hasTrait(MediaTraitType.LOAD))

                                      {

                                        netStreamLoadTrait = mediaElement.getTrait(MediaTraitType.LOAD) as NetStreamLoadTrait;

                                        netStreamLoadTrait.addEventListener(LoadEvent.LOAD_STATE_CHANGE, onLoaded);

                               

                                      }

                                    }

                                  }

                                 

                                 

                                  private function onLoaded(event:LoadEvent):void

                                  {

                                    netStream = netStreamLoadTrait.netStream;

                                    netStream.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);

                                  }

                              • 12. Re: Seeking within client buffer in OSMF player flushes the client buffer
                                ReDrUmNZ Level 1

                                Thanks for that Silviu, I'll try it tomorrow at work.

                                 

                                I was also experimenting with accessing the FMS server version in order to enable smart seeking on v3.5.3+. I don't have the code handy right now but I saw the resource gets a server version attached to it as meta data after the NetConnection is established. Whats the best way to access this? When I tried accessing it earlier today I was null or empty however my FMS is v4.x.

                                • 13. Re: Seeking within client buffer in OSMF player flushes the client buffer
                                  ReDrUmNZ Level 1

                                  Hi Silviu,

                                   

                                  I tried your suggestion however it didn't work because the Load Trait never triggered (however every other trait did). I've since figured out how to access the NetStream by combining your advice with Wei's. For anyone interested see below for the solution as of OSMF 1.6.1.

                                   

                                  var player:MediaPlayer = new MediaPlayer();

                                   

                                  player.addEventListener(MediaPlayerCapabilityChangeEvent.CAN_LOAD_CHANGE, capabilityHandler);

                                   

                                  function capabilityHandler(event:MediaPlayerCapabilityChangeEvent):void

                                  {

                                       if(event.type == MediaPlayerCapabilityChangeEvent.CAN_PLAY_CHANGE)

                                       {

                                            if (mediaElement.hasTrait(MediaTraitType.LOAD))

                                            {

                                                 nsLoadTrait= mediaElement.getTrait(MediaTraitType.LOAD) as NetStreamLoadTrait;

                                                 nsLoadTrait.addEventListener(LoadEvent.LOAD_STATE_CHANGE, netStreamLoadHandler);

                                            }

                                       }

                                  }

                                   

                                  function netStreamLoadHandler(e:LoadEvent):void

                                  {

                                       var ns:NetStream = nsLoadTrait.netStream;

                                      

                                       // It would probably pay to ensure the FMS server version is greater than 3.5.3 before enabling smart seek.

                                       ns.inBufferSeek = true;

                                       ns.backBufferTime = 30;

                                   

                                       nsLoadTrait.removeEventListener(LoadEvent.LOAD_STATE_CHANGE, netStreamLoadHandler);

                                  }

                                   

                                   

                                  Additionally how do I access the FMS Server Version? I see NetNegotiator adds it as MetaData on line 309 after sucessfully connecting a NetConnection.

                                  e.g. resource.addMetadataValue(MetadataNamespaces.FMS_SERVER_VERSION_METADATA, event.info.data.version);

                                   

                                  Is NetNegotiator used by default when using the DefaultMediaFactory? When I try to access that data it's always null. I know for a fact that my FMS does return event.info.data.version after NetConnection.Connect.Success because I can manually access it outside of OSMF. I noticed in NetLoader the supportsStreamReconnect() function defaults to true even if that metadata is null. Is that metadata unreliable?

                                   

                                  Cheers,

                                   

                                  Tim

                                  • 14. Re: Seeking within client buffer in OSMF player flushes the client buffer
                                    ReDrUmNZ Level 1

                                    Now that I've enabled SmartSeeking I'm noticing an 2-10 second delay before the video display (MediaPlayer) visually updates. The smart seeking is occuring within the buffer correctly/instantly, I can hear the audio play and the TimeEvent.CURRENT_TIME_CHANGE event fires/updates however the video remains frozen on a still frame for 2-10 seconds. Any ideas?