1
我有一個Flash應用程序連接到EvoStream服務器,通過RTMP接收視頻。我從SNC相機模擬器和物理相機獲取視頻。當我第一次啓動時,物理攝像機顯示視頻,但模擬攝像機不顯示。保持播放器運行,我關閉SNC程序並出現一幀視頻。當我重新啓動SNC程序時,視頻現在可以在客戶端正常播放。Flash NetStream接收數據但並不總是顯示它
當我打印出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 + " 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);
}
}