Skip navigation
DSuess_33
Currently Being Moderated

Seeking in NetStream with appendBytes

May 26, 2010 3:20 AM

Hello,

i hope anyone can help me.

 

I  play a video over the NetStream.appendBytes() method.


If  I use the NetStream.seek() method the video stop and I get the NetStreamStatusEvent ""NetStream.Seek.Notify"

 

I have read in the documentation that the buffers is flushing. I have to call the NetStream.appendBytesAction(NetStreamAppendBytesAction) method

 

But after that nothing happend.

 

Any ideas?

 

Code:

 

     NetStream:

 

        ns = new NetStream(_netConnection);
        ns.bufferTime = _bufferTime;
        ns.addEventListener(NetStatusEvent.NET_STATUS, netStreamStatusHandler);
        ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
        var client:Object = new Object();
        client.onMetaData = metaDataObject;
        ns.client = client;
        ns.play(null);               
        ns.appendBytes(bytes);

 

 

      Seeking:

 

        ns.seek(seekPos);

 

 

     NetStreamStatus:

 

        case "NetStream.Seek.Notify" :
            trace("NetStream Notify");
            ns.appendBytesAction(NetStreamAppendBytesAction.RESET_SEEK);
            break;

 

 

Thx

 
Replies
  • Currently Being Moderated
    May 26, 2010 8:33 PM   in reply to DSuess_33

    It may be better if you ask in the appropriate developers forum (Flash, Flex, ActionScript, ...?).

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 15, 2010 7:23 AM   in reply to DSuess_33

    Hi,

    I have exactly the same problem,

    Did you manage to solve this problem yet?

     

    thanks

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 3, 2010 9:00 PM   in reply to rotbardk4

    Anybody has any luck with this issue?

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 8, 2010 10:55 PM   in reply to DSuess_33

    Are you writing any additional bytes to your stream after the seek?  As per the API Documentation, calling seek() in this mode (what Adobe refers to as "Data Generation Mode") flushes the stream's playout and FIFO buffers.  In essence, it discards any data previously written to the stream, and leaves you with a blank slate.  So really the use-case goes like:

     

    //start playing
    ns.play(null);                
    ns.appendBytes(bytes);  //write the bytes to play from the beginning of the stream
     
    //seek 
    ns.seek(0);  //the parameter to seek() is irrelevant, as both the playout and FIFO buffers will be cleared
    ns.appendBytesAction(NetStreamAppendBytesAction.RESET_SEEK);  //you can do this in NetStreamStatus if you want
    ns.appendBytes(seekPosBytes);  //write the bytes to play from the desired stream position
    

     

     

    ...so basically there is no built-in way to seek over already appended data.  The idea is that you append data to the stream more-or-less in real-time, and to perform a seek you flush whatever is in the buffers and start appending data from the desired point.  Playback from the NetStream itself is always linear in this usage mode (i.e. it just plays whatever is written to it, in the order it is written, until told to stop), the only variable is what you pass to it via the appendBytes() calls.

     

    Now if you think that's a bit confusing, I don't blame you.  I'd blame Adobe for having an API function that does completely different things depending upon which mode the NetStream is being used in.  I think it may have been more appropriate to have seek() throw an exception when called in Data Generation mode, and have a flush() method that performs the current functionality of clearing the playout and FIFO buffers.  But anyways, I digress.

     
    |
    Mark as:
  • Currently Being Moderated
    May 30, 2012 7:00 AM   in reply to adam.roth

    Do you have more code for this example ??

     

    seekPosBytes = how get it ?

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 8, 2012 2:43 PM   in reply to Pimenov-O

    from the keyframes informations contained in the metadata

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 21, 2012 12:59 AM   in reply to Bl0tCh

    how do i get the keyframes info? I've been trying various ways but i cant seem to be able to make it work

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 28, 2012 12:42 AM   in reply to Fyrlandt

    I got it worked....My code is,

     

    // onmetadata function get all timestamp and corresponding fileposition..

    function onMetaData(infoObject:Object):void {

     

                                                      for (var propName:String in infoObject) {

     

                                                                if (propName == "keyframes")

                                                                {

                                                                                var kfObject:Object = infoObject[propName];

                                                                                var timeArr:Array          =          kfObject["times"];

                                                                                var byteArr:Array          =          kfObject["filepositions"];

     

                                                                          for(var i:int=0;i<timeArr.length;i++)

                                                                          {

                                                                                     var tagPos:int                      = byteArr[i];//Read the tag size;

                                                                                     var timestamp:Number = timeArr[i];//read the timestamp;

                                                                                     tags.push({timestamp:timestamp,tagPos:tagPos});

     

                                                                          }

                                                                }

     

    // onseek click get approximate timestamp and its fileposition

     

         protected function seek_click(seektime:Number):void

                                  {

     

                                                      var cTime:Number          =          0;

                                                      var pTime:Number          =          0;

     

                                                      for (var i:int=1; i<tags.length; i++)

                                                      {

                                                                cTime  = tags[i].timestamp;

                                                                pTime          =          tags[i-1].timestamp;

     

                                                                if(pTime < seektime)

                                                                {

                                                                          if(seektime < cTime){

                                                                                     seekPos                    =          tags[i-1].tagPos;

                                                                                     stream.seek(pTime);

                                                                                     break;

                                                                          }

                                                                }

                                                      }

                                  }

     

    /// append bytes on seekposition

     

     

         private function netStatusHandler(event:NetStatusEvent):void {

     

         switch (event.info.code) {

     

              case "NetStream.Seek.Notify" :

     

                                                                stream.appendBytesAction(NetStreamAppendBytesAction.RESET_SEEK);

     

                                                                totalByteArray.position = seekPos;

     

                                                                var bytes:ByteArray = new ByteArray();

                                                                totalByteArray.readBytes(bytes);

                                                                stream.appendBytes(bytes);

     

                                                                stream.resume();

                                                                break;

              }

    }

     

     

    after searching a lot i got this solution....just try..!!!!

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 30, 2012 11:41 PM   in reply to aswathykrishnan

    Hi Krishnan,

     

    I was trying this code on my flv file which has no keyframes. So, will it not work without keyframes. If yes, then, the above code not worked for me. May you help me out from it?

     

    Thanks,

    Saurabh

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 3, 2012 5:34 AM   in reply to subham

    Hi Saurabh,

     

    Your solution is to inject MetaData keyframes into flv file.

    Use some injector tool, fe. FLV MetaData Injector

     

    http://www.buraks.com/flvmdi/

     

    Good luck!

     

    Fiodor

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points