AS3 - How do I know if a video has ended?

I use flash.net.NetStream and flash.media.Video to play .flv, here is the 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);

What the video plays, but how can I know WHEN the video was played from start to finish? How do I know if a video has been played ALL of its length?

PS: Sorry for my bad english.

+5
source share
4 answers

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

The code "NetStream.Play.Complete"does not exist.

stream.addEventListener(NetStatusEvent.NET_STATUS, statusChanged);

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

, , ( ), - ( )

PS: .

+14

:

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

( , , Play.Stop Buffer.Empty)

+1

, stream.client, 'onPlayStatus'

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html#event:onPlayStatus

, - , :

function myFunction(obj:Object):void
{
    //do something here
}
stream.client = {onPlayStatus: myFunction}
0

NET_STATUS:

stream.addEventListener(NetStatusEvent.NET_STATUS, statusChanged);

function statusChanged(stats:NetStatusEvent) {
    if (stats.info.code == 'NetStream.Play.Complete') {
         // do some stuff
    }
}
0

All Articles