如何暂停和重新启动 NetStream 对象?
How to pause and restart a NetStream object?
我有一个 NetStream 对象,基于以下代码:
streamID = "mystreamkey";
videoURL = "rtmp://mystreamurl";
vid = new Video();
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, onConnectionStatus);
nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
nc.client = { onBWDone: function():void{}, streamConnected: streamConnected, streamDisconnected: streamDisconnected };
nc.connect(videoURL);
...
metaListener = new Object();
metaListener.onMetaData = received_Meta;
netStreamObj.client = metaListener;
netStreamObj.play(streamID);
vid.attachNetStream(netStreamObj);
addChild(vid);
一切正常,我还可以使用netStreamObj.pause()
暂停直播。
但是我该如何重新启动呢? netStreamObj.play()
行不通——它需要一个参数,所以我写了这个:
netStreamObj.play(streamID);
vid.attachNetStream(netStreamObj);
但这也不起作用。
如何重新启动流,以便它连接到之前连接的实时流?
How do I restart the stream, so that it connects to the live stream it
was previously connected to?
为了将来参考,请检查 NetStream API documentation for options. You'll be looking to check out the commands listed under the Public methods 部分。
您可以使用:
resume(): Resumes playback of a video stream that is paused.
用法:netStreamObj.resume();
togglePause(): Pauses or resumes playback of a stream.
用法:netStreamObj.togglePause();
我建议使用 togglePause
,因为它 自动检测 NetStream 对象的播放状态。您的 "Pause" 按钮(或 MovieClip)应该只有一个点击侦听器事件,其函数具有以下行:netStreamObj.togglePause();
。就这么简单...
我有一个 NetStream 对象,基于以下代码:
streamID = "mystreamkey";
videoURL = "rtmp://mystreamurl";
vid = new Video();
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, onConnectionStatus);
nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
nc.client = { onBWDone: function():void{}, streamConnected: streamConnected, streamDisconnected: streamDisconnected };
nc.connect(videoURL);
...
metaListener = new Object();
metaListener.onMetaData = received_Meta;
netStreamObj.client = metaListener;
netStreamObj.play(streamID);
vid.attachNetStream(netStreamObj);
addChild(vid);
一切正常,我还可以使用netStreamObj.pause()
暂停直播。
但是我该如何重新启动呢? netStreamObj.play()
行不通——它需要一个参数,所以我写了这个:
netStreamObj.play(streamID);
vid.attachNetStream(netStreamObj);
但这也不起作用。
如何重新启动流,以便它连接到之前连接的实时流?
How do I restart the stream, so that it connects to the live stream it was previously connected to?
为了将来参考,请检查 NetStream API documentation for options. You'll be looking to check out the commands listed under the Public methods 部分。
您可以使用:
resume(): Resumes playback of a video stream that is paused.
用法:netStreamObj.resume();
togglePause(): Pauses or resumes playback of a stream.
用法:netStreamObj.togglePause();
我建议使用 togglePause
,因为它 自动检测 NetStream 对象的播放状态。您的 "Pause" 按钮(或 MovieClip)应该只有一个点击侦听器事件,其函数具有以下行:netStreamObj.togglePause();
。就这么简单...