AS3 Netstream Video stops during seek

I’ve noted this in other areas but there is a serious bug in the netstream class or i’m not doing it right.

Here’s the deal — during the seek of a low keyframe video asset the netstream may end up sending a stop even if you try to seek to a point in the video after the last keyframe. It’s pretty consistent and very irritating.

During seek events this event is fired:

  • NetStream.Seek.Notify

And at some point during interaction with the video player the netstream will fire a series of Flush and possibly a Full event.
At this point, if you seek to a point past the last keyframe you’ll generate a:

  • NetStream.Play.Stop

and end your interaction arbitrarily.

The solution is to limit your seek values to a point prior to the second last keyframe, which you can get from the metadata on load of the video asset:

Here’s a sample of a metadatahandler:

public function onMetaData(info:Object):void {

for (var prop:String in info) {
if (typeof(info[prop]) == "object") {
var ii:Number = info[prop].length-1;
if (ii == 0) {
// it's an object as opposed to the array of other values in the metadata and a candidate for our keyframe object in the metadata.
var propy:String;
for (propy in info[prop]) {
// keyframes is the object, and times is the array of keyframe times
if (prop == "keyframes" && propy == "times") {
lastkeyframe = info[prop][propy][info[prop][propy].length - 3];
}
}
}
} else {

if (isNaN(lastkeyframe)) {

lastkeyframe = info['lastkeyframetimestamp'];

}

}
}

I’m assuming that you’re using some kind of encoder that adds the correct metadata values (Buraks FLVMDI is a good alternative). Sadly, if you can’t get the keyframes you’ll end up hacking in a negative value to the injected metadata value of ‘lastkeyframetimestamp’ which doesn’t solve the problem.

Very irritating!

About Bela Korcsog

Proud father of two children, happy husband to one wife. I've been programming various technologies and leading the development of huge projects for most of the last ten years. I've got some specific likes and dislikes through my experiences in the web site business but generally I'm pretty straightforward about it. Not a huge fan of the latest and greatest shiny toy (it took me four years to show an interest in Flash) I'm more than happy to code in any language that comes along (Actionscript is just so darn fun).
This entry was posted in Flash. Bookmark the permalink.

Comments are closed.