我必须使用 flash.media.Video 组件来播放远程视频文件,因为我在 Red5 中有一个不允许使用 VideoPlayer 的自定义身份验证机制 (CRAM-MD5)。我试图使用 OpenVideoPlayer,但它在服务器端失败(执行调用时出错:服务:null 方法:play Num Params:3 0:test/avatar.flv 1:NaN 2:NaN)。
我只需要将控制器放在 Video 组件的顶部:播放、暂停、停止、倒带、进度条。请问有人可以推荐我一个简单的观点吗?或者任何解决方案都可以!
更新: 示例代码,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>