Copy link to clipboard
Copied
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
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.see
Copy link to clipboard
Copied
It may be better if you ask in the appropriate developers forum (Flash, Flex, ActionScript, ...?).
Copy link to clipboard
Copied
Hi,
I have exactly the same problem,
Did you manage to solve this problem yet?
thanks
Copy link to clipboard
Copied
Anybody has any luck with this issue?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
thanks, it works!!!!!!!!
its necessary to append bytes beginning with an keyframe position after seek()
Copy link to clipboard
Copied
Do you have more code for this example ??
seekPosBytes = how get it ?
Copy link to clipboard
Copied
from the keyframes informations contained in the metadata
Copy link to clipboard
Copied
how do i get the keyframes info? I've been trying various ways but i cant seem to be able to make it work
Copy link to clipboard
Copied
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;//Read the tag size;
var timestamp:Number = timeArr;//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.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..!!!!
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Hi Saurabh,
Your solution is to inject MetaData keyframes into flv file.
Use some injector tool, fe. FLV MetaData Injector
Good luck!
Fiodor