Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AS3 - How to know if a video has ended?

I'm using flash.net.NetStream and flash.media.Video to play a .flv, here is some code:

var stream:NetStream = new NetStream(connection);

//next line is to avoid an error message
stream.client = {onMetaData: function(obj:Object):void {}}

var video:Video = new Video();
video.attachNetStream(stream);
stream.play("url.to/video");

addChild(video);

That plays the video, but how I can know WHEN the video has played from the beginning to the end? How to know if the video was played ALL it's length?

PS: Sorry for my bad English.

like image 565
Lucas Gabriel Sánchez Avatar asked Jul 12 '11 13:07

Lucas Gabriel Sánchez


2 Answers

Bartek answer is the most accurate but I've found that the code I need is "NetStream.Play.Stop"

The code "NetStream.Play.Complete" doesn't exist.

stream.addEventListener(NetStatusEvent.NET_STATUS, statusChanged);

function statusChanged(stats:NetStatusEvent) {
    if (stats.info.code == 'NetStream.Play.Stop') {
         trace('the video has ended');
    }
}

This works since you can't STOP the stream, only pause it (and resume it), so the only way to this status arise is to end the video playback reaching the end (and that's what I need)

PS: Sorry for my bad English.

like image 152
Lucas Gabriel Sánchez Avatar answered Nov 03 '22 01:11

Lucas Gabriel Sánchez


The code I need was:

        public function statusChanged(stats:NetStatusEvent):void 
        {
            trace(stats.info.code);
            if (stats.info.code == 'NetStream.Buffer.Empty') 
            {
                trace('the video has ended');
            }
        }

(the only change I had to make was Changing Play.Stop to Buffer.Empty)

like image 43
Nicholas Avatar answered Nov 03 '22 00:11

Nicholas