【问题标题】:Simple view for Video component视频组件的简单视图
【发布时间】:2012-09-21 13:28:05
【问题描述】:

我必须使用 flash.media.Video 组件来播放远程视频文件,因为我在 Red5 中有一个不允许使用 VideoPlayer 的自定义身份验证机制 (CRAM-MD5)。我试图使用 OpenVideoPlayer 但它在服务器端失败(执行调用时出错:服务:null 方法:play Num Params:3 0:test/avatar.flv 1:NaN 2:NaN)。

我只需要将控制器放在视频组件的顶部:播放、暂停、停止、倒带、进度条。请问有人可以推荐我一个简单的观点吗?或者任何解决方案都可以!

更新: 一个示例代码,togglePause 不能正常工作:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="640" minHeight="480"
           initialize="init();">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
    <![CDATA[
        import flash.globalization.Collator;

        import mx.utils.ObjectUtil;
        import mx.controls.Alert;

        private var nc:NetConnection;
        private var ns:NetStream;
        private var video:Video;
        private var meta:Object;
        private var videoURL:String = "test/avatar.flv";

        private function init():void {

            var params:Object = {
                user: "user",
                video_id: 2
            };

            nc = new NetConnection();
            nc.connect("rtmp://localhost/myapp", params);
            nc.client = this;
            nc.addEventListener(NetStatusEvent.NET_STATUS,onConnectionStatus);
            nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR,onErrorHandler);
            nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
        }

        private function onConnectionStatus(event:NetStatusEvent):void {

            var nsClient:Object = {};
            nsClient.onMetaData = ns_onMetaData;
            nsClient.onCuePoint = ns_onCuePoint;

            ns = new NetStream(nc);
            ns.play(videoURL);
            ns.client = nsClient;

            video = new Video();
            video.attachNetStream(ns);
            uic.addChild(video);
        }

        private function onErrorHandler(event:AsyncErrorEvent):void{
        }

        private function onSecurityError(event:SecurityErrorEvent):void{
        }

        private function ns_onMetaData(item:Object):void {
        }

        private function ns_onCuePoint(item:Object):void {
        }

        public function onBWDone():void {
        }

    ]]>
</fx:Script>
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:SpriteVisualElement id="uic" x="0" y="0" width="320" height="240" /> 
<mx:ControlBar x="10" y="330">
    <mx:Button label="Play/Pause" click="ns.togglePause();" />
    <mx:Button label="Rewind" click="ns.seek(0); ns.pause();" />
</mx:ControlBar>

【问题讨论】:

  • 我试图自己制作,但 togglePause() 出现问题 - 冻结 - 我什至没有开始将进度条作为其中的一部分......:S

标签: apache-flex video stream red5 custom-component


【解决方案1】:

我猜你正在使用 NetStream 类,它与 NetConnection 一起负责从 Red5 检索媒体。

查看 NetStream 的文档:http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html

应该有足够的方法和事件来构建所需的控件(如 play()、pause() 等)

另外,考虑研究开源媒体框架。它为构建媒体播放器提供了很好的抽象,并允许为附加功能创建插件(例如 Red5 身份验证机制)。

此外,VideoPlayer 组件是基于 OSMF 的,因此您可以开发一个自定义插件来与您的 Red5 服务器通信并将其与 Flex 的 VideoPlayer 一起使用。

【讨论】:

  • 正如我所提到的,我尝试自己制作控件,但一开始我遇到了一个错误:播放/暂停并不像看起来那么容易。 Pause()-resume() 不起作用,togglePause() 暂停但会返回 1-2 秒,然后如果我再次调用它,它会持续几秒并冻结。我希望你明白我不想更深入地浪费时间与自定义搜索器等。
  • 那你能分享一下你如何使用 flash.media.Video 的代码吗?
猜你喜欢
  • 2011-04-30
  • 2013-06-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多