我在流式传输视频时遇到问题。随机不显示视频,但随着播放头的移动和音频的声音,视频正在播放。
这很奇怪,因为如果我按下暂停然后播放视频就会出现,如果我让它全屏显示它也会出现。
private var videoURL:String = "filename.f4v";
private function setupConnection():void
{
connection = new NetConnection();
connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
connection.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onErrorConnect);
connection.connect("rtmp://url to my streaming server");
}
private function netStatusHandler(event:NetStatusEvent):void
{
trace("event.info.code "+event.info.code);
switch (event.info.code) {
case "NetConnection.Connect.Success":
connectStream();
break;
case "NetStream.Play.Start":
onPlayVideoHandler();
break;
case "NetStream.Play.StreamNotFound":
trace("Stream not found: " + videoURL);
break;
default :
}
}
private function onErrorConnect(event:AsyncErrorEvent):void
{
trace("onErrorConnect: " + event);
}
private function securityErrorHandler(event:SecurityErrorEvent):void
{
trace("securityErrorHandler: " + event);
}
private function connectStream():void
{
stream = new NetStream(connection);
stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
stream.bufferTime = 10;
var client:Object = new Object();
client.onMetaData = onMetaData;
stream.client = client;
video = new Video(200, 200);
video.name = "video";
video.addEventListener(Event.ADDED_TO_STAGE, videoAddedToStage)
video.attachNetStream(stream);
video.smoothing = true;
video.x = 0;
video.y = 0;
mainHolder.addChild(video);
stream.play(videoURL, 0, 100, true);
stream.seek(0);
}
private function onPlayVideoHandler():void
{
// add Controls
}
好的,我发现它不显示的原因是因为视频有时具有 0 像素的宽度和高度。有人知道为什么它会返回这些值吗?这与 rtmp 流媒体视频的性质有关吗?