代码之家  ›  专栏  ›  技术社区  ›  mga

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

  •  0
  • mga  · 技术社区  · 15 年前

    我有一些FLV视频文件要由一个Flash视频播放器按顺序复制。假设v1.flv和v2.flv。我希望玩家在v1.flv结束后开始玩v2.flv。根据 this forum , the onPlayStatus 不会在渐进式飞行物中开火。可以做什么?下面是我正在尝试的一小段内容:

    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
    

    任何帮助都将不胜感激!

    3 回复  |  直到 15 年前
        1
  •  1
  •   zeh    15 年前

    您仍然可以通过一个附加的netstatus伪事件来完成此操作:当视频停止时,请检查时间。

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

    Caveats:

    1. 您必须等待元数据信息(在示例中是“nsinfo”),然后才能获得持续时间:

      // On nsClient
      public function onMetaData(info:Object):void {
          nsInfo = info;
      }
      
    2. 它不是很精确,因此“-0.1”使时间比较更安全

        2
  •  0
  •   PatrickS    15 年前

    您也可以尝试OSMF框架,这是Adobe提供的简化闪存介质交付的功能。OSMF实现了开箱即用的顺序播放。 http://www.osmf.org/developers.html

    查看此日志以获取信息和示例代码 http://www.rblank.com/

        3
  •  0
  •   mga    15 年前

    我用了查理男孩的一部分 suggestion 适应 MediaStream.as 每100毫秒检查一次 time 性质 NetStream 是一样的(它卡在最后…或者只是卡住了,但我的具体情况不太可能)。

    我添加了三个属性 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毫秒的“卡帧”。对我的特殊需要来说还不错。

    谢谢大家的意见。