Detecting the end of FLV stream in Actionscript 3
There is an issue with this post, read it and then read this:
http://blog.code-head.com/detecting-the-end-of-flv-stream-in-actionscript-3-part-2
This is also one of those things that I couldn’t really find a real solution to online, so with some tests and experiments, I came up with this solution which I’m not sure if it’s the best solution.
First you will need to attach an event to your incoming stream, assuming your stream is clientStream:
/* ... */ clientStream = new NetStream(serverConnection); clientStream.addEventListener(NetStatusEvent.NET_STATUS, PlayerStatusHandler);
Then you will need a member variable or a variable in the global scope to keep the latest status:
var playerLastEvent:String = new String();
Now the PlayerStatusHandler which again, I don’t think it’s very pretty:
function PlayerStatusHandler(event:NetStatusEvent) { if (playerLastEvent == "NetStream.Buffer.Flush" && event.info.code == "NetStream.Buffer.Empty") { /* Stopped */ StopPlayback(event); /* Or any other thing you want to do */ } else if (playerLastEvent == "NetStream.Buffer.Flush" && event.info.code != "NetStream.Buffer.Empty") playerLastEvent = ""; /* Sometimes it throws the Flush event */ else if (event.info.code == "NetStream.Buffer.Flush") playerLastEvent = "NetStream.Buffer.Flush"; }
So as you can see, we are looking for the Flush event that is followed by an Empty event.
This is just tested on my connection and I don’t really know how this works on slow connections, where the buffer is empty often but maybe you can tell me
I wish there was an event to show the real end of the stream.
Permalink for Detecting the end of FLV stream in Actionscript 3


Detecting the end of FLV stream in Actionscript 3, part 2 said,
September 24, 2008 @ 4:42 pm
[...] Detecting the end of FLV stream in Actionscript 3, part 2 [...]
Panel said,
October 7, 2008 @ 8:15 am
use
NetStream.Play.Stop
Codehead said,
October 7, 2008 @ 5:27 pm
Unfortunately it didn’t work for me, it was thrown in the middle of the stream.
There are also so many posts all over the place about it.
In my simple application I ended up using onMetaHandler and get the duration.
I would appreciate if you could explain this a little more though, I’m learning.