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.
Hamid Alipour is a partner in Codehead, LLP with his wife, Tess. Hamid speaks 12 markup and programming languages [Yes, 12: PHP, CSS, Ajax, JavaScript, HTML/XHTML, Java, Python, C/C++, ASP, Visual Basic, Scheme and Action Script]; has a penchant for solving the unsolvable; an affinity for clean, hand-written code and is a Zend Certified 
[...] Detecting the end of FLV stream in Actionscript 3, part 2 [...]
Pingback
use
NetStream.Play.Stop
Comment
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.
Comment
In NetStream.Play.Stop, check if NetStream.time >= duration. You can get the video duration from onMetaHandler.
Comment
Yea, having a real event for the end of the video would be unthinkable!
I’ve found that in Flash 10, playing back mp4, sometimes the EMPTY event isn’t ever thrown at the end – but sometimes it is. Time for more hacks!
Comment