2016-02-29 66 views
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); 
} 
} 

回答

0

嘗試增加:

connection.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler); 
connection.client = { onBWDone: function():void{} }; 

然後確保onFCSubscribeonBWDone存在,因爲Flash播放器,可能需要給他們打電話...

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); 
}