如何检测渐进式 Flash 视频 FLV 的剪辑结尾?

发布于 2024-09-19 09:26:43 字数 1647 浏览 5 评论 0原文

我有一些 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦里兽 2024-09-26 09:26:43

您仍然可以通过一个额外的 netStatus 伪事件来做到这一点:当视频停止时,检查时间。

switch(event.info.code) {
    (...)
    case "NetStream.Play.Stop":
        if (ns.time >= nsClient.nsInfo.duration - 0.1) trace ("video has finished");
        break;
}

注意事项:

  1. 在获得持续时间之前,您必须等待元数据信息(即示例中的“nsInfo”):

    // 在 nsClient 上
    公共函数 onMetaData(info:Object):void {
        nsInfo = 信息;
    }
    
  2. 它不是很精确,因此使用“-0.1”来使时间比较更安全

You can still do that with one additional netStatus pseudo-event: when the video stops, check the time.

switch(event.info.code) {
    (...)
    case "NetStream.Play.Stop":
        if (ns.time >= nsClient.nsInfo.duration - 0.1) trace ("video has finished");
        break;
}

Caveats:

  1. You'll have to wait for the metadata information (that's 'nsInfo' in the example) before you have the duration:

    // On nsClient
    public function onMetaData(info:Object):void {
        nsInfo = info;
    }
    
  2. It's not very precise, hence the "-0.1" to make the time comparison safer

那支青花 2024-09-26 09:26:43

您还可以尝试 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/

自此以后,行同陌路 2024-09-26 09:26:43

我最终使用了 charlie-boy 的建议的部分内容来改编< code>MediaStream.as 每 100 毫秒检查一次 NetStreamtime 属性是否相同(它卡在最后......或者可能只是卡住但我的具体情况使这种情况不太可能发生)。

我向 MediaStream 添加了三个属性:

private var last_time:Number = -1;
private var last_check:int  = 0;
private const check_delay:int = 100;

并更改了 compareTime 函数,如下所示:

    private function compareTime():void
    {
        if (isNaN(duration))
        {
            // when there is no metadata duration
            if (getTimer() - last_check > check_delay)
            {
                // enough time has passed since last check
                if (last_time==this.time)
                {
                    timer.stop();
                    timer.removeEventListener(TimerEvent.TIMER, onTimer);
                    dispatchEvent(new StreamEvent(StreamEvent.COMPLETE, null));
                }
                else
                {
                    last_check = getTimer();
                    last_time = this.time;
                }
            }
        }
        else if(!isNaN(duration) && this.time >= duration)
        {
            timer.removeEventListener(TimerEvent.TIMER, onTimer);
            dispatchEvent(new StreamEvent(StreamEvent.COMPLETE, null));
        }
    }

最坏的情况是在加载下一个剪辑之前出现 100 毫秒的“卡帧”。对于我的特定需求来说还不错。

感谢大家的意见。

I ended using part of charlie-boy's suggestion adapting MediaStream.as to check every 100ms if the time property of the NetStream 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:

private var last_time:Number = -1;
private var last_check:int  = 0;
private const check_delay:int = 100;

and changed the compareTime function like this:

    private function compareTime():void
    {
        if (isNaN(duration))
        {
            // when there is no metadata duration
            if (getTimer() - last_check > check_delay)
            {
                // enough time has passed since last check
                if (last_time==this.time)
                {
                    timer.stop();
                    timer.removeEventListener(TimerEvent.TIMER, onTimer);
                    dispatchEvent(new StreamEvent(StreamEvent.COMPLETE, null));
                }
                else
                {
                    last_check = getTimer();
                    last_time = this.time;
                }
            }
        }
        else if(!isNaN(duration) && this.time >= duration)
        {
            timer.removeEventListener(TimerEvent.TIMER, onTimer);
            dispatchEvent(new StreamEvent(StreamEvent.COMPLETE, null));
        }
    }

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文