如何检测渐进式 Flash 视频 FLV 的剪辑结尾?
我有一些 FLV 视频文件要通过 Flash 视频播放器顺序再现。假设 v1.flv 和 v2.flv。我希望玩家在 v1.flv 结束后开始播放 v2.flv。根据此论坛,onPlayStatus
不会在渐进式 FLV 中触发。可以做什么?下面是我尝试的片段:
public class MyClass extends Sprite {
private var nc : NetConnection;
private var ns : NetStream;
private var vid : Video;
private var vidURL : String = "v1.flv";
public function MyClass() {
var nsClient:Object = {};
nsClient.onPlayStatus = client_onPlayStatus;
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
nc.connect(null);
ns = new NetStream(nc);
ns.play(vidURL);
ns.client = nsClient;
vid = new Video();
vid.attachNetStream(ns);
addChild(vid);
}
private function netStatusHandler(event : NetStatusEvent) : void {
trace(event.info.code);
switch(event.info.code) {
case "NetConnection.Connect.Success":
trace("Loaded stream: " + vidURL);
break;
case "NetStream.Play.StreamNotFound":
trace("Stream not found: " + vidURL);
break;
default:
}
}
private function client_onPlayStatus(event:Object) : void {
trace("status=" + event.info.code);
}
}
跟踪输出中显示的唯一文本是:
NetConnection.Connect.Success
Loaded stream: /path/to/v1.flv
任何帮助将不胜感激!
I have some FLV video files to be reproduced sequentially by a Flash video player. Suppose v1.flv and v2.flv. I want the player to start playing v2.flv once v1.flv has reached the end. According to this forum, the onPlayStatus
does not fire in progressive FLVs. What can be done? A snippet of what I am trying below:
public class MyClass extends Sprite {
private var nc : NetConnection;
private var ns : NetStream;
private var vid : Video;
private var vidURL : String = "v1.flv";
public function MyClass() {
var nsClient:Object = {};
nsClient.onPlayStatus = client_onPlayStatus;
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
nc.connect(null);
ns = new NetStream(nc);
ns.play(vidURL);
ns.client = nsClient;
vid = new Video();
vid.attachNetStream(ns);
addChild(vid);
}
private function netStatusHandler(event : NetStatusEvent) : void {
trace(event.info.code);
switch(event.info.code) {
case "NetConnection.Connect.Success":
trace("Loaded stream: " + vidURL);
break;
case "NetStream.Play.StreamNotFound":
trace("Stream not found: " + vidURL);
break;
default:
}
}
private function client_onPlayStatus(event:Object) : void {
trace("status=" + event.info.code);
}
}
The only text that shows up in the trace output is:
NetConnection.Connect.Success
Loaded stream: /path/to/v1.flv
Any help will be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您仍然可以通过一个额外的 netStatus 伪事件来做到这一点:当视频停止时,检查时间。
注意事项:
在获得持续时间之前,您必须等待元数据信息(即示例中的“nsInfo”):
它不是很精确,因此使用“-0.1”来使时间比较更安全
You can still do that with one additional netStatus pseudo-event: when the video stops, check the time.
Caveats:
You'll have to wait for the metadata information (that's 'nsInfo' in the example) before you have the duration:
It's not very precise, hence the "-0.1" to make the time comparison safer
您还可以尝试 osmf 框架,这是 adobe 提供的用于简化 Flash 媒体交付的产品。 osmf 实现开箱即用的顺序播放。
http://www.osmf.org/developers.html
查看此博客以获取信息和信息示例代码
http://www.rblank.com/
you could also try the osmf framework , adobe's offer to streamline flash media delivery. osmf implements sequential playing out of the box.
http://www.osmf.org/developers.html
check this blog for info & sample code
http://www.rblank.com/
我最终使用了 charlie-boy 的建议的部分内容来改编< code>MediaStream.as 每 100 毫秒检查一次
NetStream
的time
属性是否相同(它卡在最后......或者可能只是卡住但我的具体情况使这种情况不太可能发生)。我向
MediaStream
添加了三个属性:并更改了
compareTime
函数,如下所示:最坏的情况是在加载下一个剪辑之前出现 100 毫秒的“卡帧”。对于我的特定需求来说还不错。
感谢大家的意见。
I ended using part of charlie-boy's suggestion adapting
MediaStream.as
to check every 100ms if thetime
property of theNetStream
is the same (it's stuck in the end... or maybe just stuck but my specific situation will make that unlikely).I added three properties to
MediaStream
:and changed the
compareTime
function like this:The worst case scenario is a 100ms "stuck frame" before loading the next clip. Not so bad for my specific need.
Thanks all for the input.