AS3 - 如何知道视频已经结束?已经结束、视频

2023-09-09 21:48:04 作者:↘姐的高傲无人能及。

我使用flash.net.NetStream在和flash.media.Video发挥FLV的,这里是一些code:

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);

这是播放视频,但我怎么知道什么时候该视频已经从开始到结束播放?如何知道视频被演奏了所有的IT的长度?

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:对不起,我的英语不好

PS: Sorry for my bad English.

推荐答案

Bartek答案是最准确的,但我发现,code我需要的是NetStream.Play.Stop

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

在code NetStream.Play.Complete不存在。

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:对不起,我的英语不好

PS: Sorry for my bad English.