Using the NetConnection Class
我正在尝试使用 NetConnection 类连接到外部服务器上的实时视频源。我已将其设置为在用户单击"播放"按钮时开始播放我的视频,但是,每次单击"播放"按钮时,这都会出现在我的输出中:
ArgumentError:错误 #2126:必须连接 NetConnection 对象。
在 flash.net::NetStream/ctor()
在 flash.net::NetStream()
在 Over/connectLiveStream()[Over::frame2:31]
关于为什么这不起作用的任何想法?这是(我认为相关的)代码:
1 2 3 4 5 6 7 8 9 10 | if (playVid.label =="Play") { nc = new NetConnection(); nc.objectEncoding = flash.net.ObjectEncoding.AMF0; nc.connect("rtmp://my.rtmp.server:1935/live/"); nsPlay = new NetStream(nc); nsPlay.play("livestream.flv"); } |
提前致谢。
我从 adobe 文档站点复制此内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | package { import flash.display.Sprite; import flash.events.*; import flash.media.Video; import flash.net.NetConnection; import flash.net.NetStream; public class NetStatusEventExample extends Sprite { private var videoURL:String ="Video.flv"; private var connection:NetConnection; private var stream:NetStream; public function NetStatusEventExample() { connection = new NetConnection(); connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler); connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); connection.connect(null); } private function netStatusHandler(event:NetStatusEvent):void { switch (event.info.code) { case"NetConnection.Connect.Success": connectStream(); break; case"NetStream.Play.StreamNotFound": trace("Unable to locate video:" + videoURL); break; } } private function connectStream():void { var stream:NetStream = new NetStream(connection); stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler); stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler); var video:Video = new Video(); video.attachNetStream(stream); stream.play(videoURL); addChild(video); } private function securityErrorHandler(event:SecurityErrorEvent):void { trace("securityErrorHandler:" + event); } private function asyncErrorHandler(event:AsyncErrorEvent):void { // ignore AsyncErrorEvent events. } } } class CustomClient { public function onMetaData(info:Object):void { trace("metadata: duration=" + info.duration +" width=" + info.width +" height=" + info.height +" framerate=" + info.framerate); } public function onCuePoint(info:Object):void { trace("cuepoint: time=" + info.time +" name=" + info.name +" type=" + info.type); } } |
希望这可以提供帮助,如果它引发安全错误,您还需要在您连接的流媒体服务器上设置跨域策略文件。
链接:
- ActionScript 3.0 语言和组件参考
- 跨域文件规范
- Flash 电影的跨域策略