Flash NetStream 接收数据但并不总是显示它
Posted
技术标签:
【中文标题】Flash NetStream 接收数据但并不总是显示它【英文标题】:Flash NetStream receiving data but not always displaying it 【发布时间】:2016-02-29 17:08:50 【问题描述】:我有一个 Flash 应用程序,它连接到 EvoStream 服务器以通过 RTMP 接收视频。我从 SNC Camera Emulator 和物理相机采购视频。当我第一次启动时,物理相机会显示视频,但模拟相机不会。保持播放器运行,我关闭了 SNC 程序,然后出现了一帧视频。当我重新启动 SNC 程序时,视频现在可以在客户端正常播放。
当我打印出 NetStream.info.currentBytesPerSecond 时,无论视频是否正在播放,我都会得到类似的值。
下面是负责显示视频的客户端代码;它与Adobe提供的示例代码基本相同。
package
import flash.display.Sprite;
import flash.events.NetStatusEvent;
import flash.events.SecurityErrorEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.events.Event;
public class testRTMP extends Sprite
private var connection:NetConnection;
private var stream:NetStream;
private var video:Video = new Video();
private var sID: String;
public function testRTMP(serverURL: String, streamId : String)
sID = streamId;
connection = new NetConnection();
connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
connection.connect(serverURL);
private function netStatusHandler(event:NetStatusEvent):void
switch (event.info.code)
case "NetConnection.Connect.Success":
connectStream();
break;
case "NetStream.Play.StreamNotFound":
trace("Stream not found: " + sID);
break;
private function securityErrorHandler(event:SecurityErrorEvent):void
trace("securityErrorHandler: " + event);
private function connectStream():void
addChild(video);
var stream:NetStream = new NetStream(connection);
stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
stream.client = new CustomClient();
video.attachNetStream(stream);
stream.play(sID);
class CustomClient
public function onMetaData(info:Object):void
trace("metadata: duration=" + info.duration + " framerate=" + info.framerate);
public function onCuePoint(info:Object):void
trace("cuepoint: time=" + info.time + " name=" + info.name + " type=" + info.type);
【问题讨论】:
【参考方案1】:尝试添加:
connection.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
connection.client = onBWDone: function():void ;
然后确保 onFCSubscribe
和 onBWDone
存在,因为 Flash Player 可能需要调用它们...
public function asyncErrorHandler(event:AsyncErrorEvent):void
trace("asyncErrorHandler.." + "\r");
public function onFCSubscribe (info:Object) : void
trace("onFCSubscribe - succesful");
public function onBWDone (...rest) : void
var p_bw:Number;
if (rest.length > 0)
p_bw = rest[0];
trace("bandwidth = " + p_bw + " Kbps.");
也可以尝试删除var stream:NetStream = etc...
这一行。
private function connectStream() : void
addChild(video);
//var stream:NetStream = new NetStream(connection); //# Is already a (private) var...
stream = new NetStream(connection);
stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
stream.client = new CustomClient();
video.attachNetStream(stream);
stream.play(sID);
【讨论】:
以上是关于Flash NetStream 接收数据但并不总是显示它的主要内容,如果未能解决你的问题,请参考以下文章
AngularJS:范围值改变,但并不总是适用于 ng-class
RED5 1.0 录制问题 NetStream.Buffer.Empty