11 Replies Latest reply on Nov 3, 2012 5:34 AM by Tomasz Świerszcz

    Seeking in NetStream with appendBytes

    DSuess_33 Level 1


      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?






              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;










              case "NetStream.Seek.Notify" :
                  trace("NetStream Notify");




        • 1. Re: Seeking in NetStream with appendBytes
          pwillener Level 8

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

          • 2. Re: Seeking in NetStream with appendBytes
            rotbardk4 Level 1


            I have exactly the same problem,

            Did you manage to solve this problem yet?



            • 3. Re: Seeking in NetStream with appendBytes
              temp1125 Level 1

              Anybody has any luck with this issue?

              • 4. Re: Seeking in NetStream with appendBytes
                adam.roth Level 1

                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.appendBytes(bytes);  //write the bytes to play from the beginning of the stream
                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.

                • 5. Re: Seeking in NetStream with appendBytes
                  DSuess_33 Level 1

                  thanks, it works!!!!!!!!


                  its necessary to append bytes beginning with an keyframe position after seek()

                  • 6. Re: Seeking in NetStream with appendBytes
                    Pimenov Oleg Level 1

                    Do you have more code for this example ??


                    seekPosBytes = how get it ?

                    • 7. Re: Seeking in NetStream with appendBytes
                      Bl0tCh Level 1

                      from the keyframes informations contained in the metadata

                      • 8. Re: Seeking in NetStream with appendBytes
                        Fyrlandt Level 1

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

                        • 9. Re: Seeking in NetStream with appendBytes
                          aswathykrishnan Level 1

                          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;






                          // 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;








                          /// append bytes on seekposition



                               private function netStatusHandler(event:NetStatusEvent):void {


                               switch (event.info.code) {


                                    case "NetStream.Seek.Notify" :




                                                                                      totalByteArray.position = seekPos;


                                                                                      var bytes:ByteArray = new ByteArray();










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

                          • 10. Re: Seeking in NetStream with appendBytes
                            subham Level 1

                            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?




                            • 11. Re: Seeking in NetStream with appendBytes
                              Tomasz Świerszcz Level 1

                              Hi Saurabh,


                              Your solution is to inject MetaData keyframes into flv file.

                              Use some injector tool, fe. FLV MetaData Injector




                              Good luck!