In your code, playback of your second video is triggered by the message NetStream.Buffer.Empty
. That message can get dispatched for several reasons, as well as when playback of a video ends. For example when streaming (which I know you're not doing), NetStream.Buffer.Empty
can get dispatched when there is a network problem. This is definitely the cause of your problem, but it's not clear why sometimes the buffer empty message gets dispatched right away.
The first thing I would do is modify your NetStatusEvent
listener so that it traces out all of the messages that are being dispatched. That way you can see the sequence of events that occurs when this problem happens.
And second, you should try using another message to trigger playback of the second video. I'm not 100% sure, but I think the message NetStream.Play.Stop
is what you want (this gets dispatched when the end of the video is reached, as well as when you programmatically stop playback). The full list of messages you get from a NetStatusEvent
is here.
Incorporating both of these suggestions, your NetStatusEvent
handler might look like this:
function NCListener(e:NetStatusEvent)
{
var code:String = e.info.code;
trace("code: ", code);
if (code == "NetStream.Record.Stop"
ns.play("video_2.flv");
}
Finally, you might want to add other event listeners to the NetStream
. It dispatches an IOErrorEvent
and AsyncErrorEvent
... perhaps you're getting one of these when the problem happens.