這個人至少讓我去了一個星期。我正試圖將錄像文件錄製到AMS。幾乎所有的時間都可以工作,除了10或15個記錄會話中的每一個之外,當我關閉流時,我從AMS的NetStream上不會收到'NetStream.Unpublish.Success'。當發生這種情況時,我使用rtmpt連接到AMS,它似乎在rtmp上運行良好。此外,似乎這隻發生在Mac上的Safari,但由於它如此間歇,我並不真正相信。這是我的基本流程:AMS在rtmpt上沒有收到取消發佈的命令有時候
// just a way to use promises with netStatusEvents
private function netListener(code:String, netObject:*):Promise {
var deferred:Deferred = new Deferred();
var netStatusHandler:Function = function (event:NetStatusEvent):void {
if (event.info.level == 'error') {
deferred.reject(event);
} else if (event.info.code == code) {
deferred.resolve(netObject);
// we want this to be a one time listener since the connection can swap between record/playback
netObject.removeEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
}
};
netObject.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
return deferred.promise;
}
// set up for recording
private function initRecord():void {
Settings.recordFile = Settings.uniquePrefix + (new Date()).getTime();
// detach any existing NetStream from the video
_view.video.attachNetStream(null);
// dispose of existing NetStream
if (_videoStream) {
_videoStream.dispose();
_videoStream = null;
}
// disconnect before connecting anew
(_nc.connected ? netListener('NetConnection.Connect.Closed', _nc) : Promise.when(_nc))
.then(function (nc:NetConnection):void {
netListener('NetConnection.Connect.Success', _nc)
.then(function (nc:NetConnection):void {
_view.video.attachCamera(_webcam);
// get new NetStream
_videoStream = getNetStream(_nc);
ExternalInterface.call("CTplayer." + Settings.instanceName + ".onRecordReady", true);
}, function(error:NetStatusEvent):void {
ExternalInterface.call("CTplayer." + Settings.instanceName + ".onError", error.info);
});
_nc.connect(Settings.recordServer);
}); // end ncClose
if (_nc.connected) _nc.close();
}
// stop recording
private function stop():void {
netListener('NetStream.Unpublish.Success', _videoStream)
.then(function (ns:NetStream):void {
ExternalInterface.call("CTplayer." + Settings.instanceName + ".onRecordStop", Settings.recordFile);
});
_videoStream.attachCamera(null);
_videoStream.attachAudio(null);
_videoStream.close();
}
// start recording
private function record():void {
netListener('NetStream.Publish.Start', _videoStream)
.then(function (ns:NetStream):void {
ExternalInterface.call("CTplayer." + Settings.instanceName + ".onRecording");
});
_videoStream.attachCamera(_webcam);
_videoStream.attachAudio(_microphone);
_videoStream.publish(Settings.recordFile, "record"); // fires NetStream.Publish.Success
}
更新 我現在使用的每個連接嘗試新的NetConnection,也不會強迫80端口(見下面我的回答')。這並沒有解決我的連接問題,只是使實例更少見。現在像每個星期左右,我仍然有一些隨機失敗的阿姆斯或閃光燈。最近有人做了錄音,然後Flash播放器無法加載視頻進行播放。 ams日誌顯示連接嘗試,然後什麼都沒有。當我加載元數據時,至少應該記錄一個播放事件。這非常令人沮喪,也無法調試。
您是否嘗試過使用wireshark並實際檢查? – bond 2014-11-25 00:39:43
這可能是一個**「太快檢查」**問題?你可以做一個嘗試/抓住,如果它失敗的unpublish命令你等一會再重新嘗試取消發佈..?我認爲RTMPT(作爲RTMP等的HTTP包裝器)的本質有時會引起打嗝,所以或許定時重試可能會有所幫助。 – 2014-11-26 06:52:02
我遇到完全相同的問題,您是否曾找到解決方案?如果沒有收到'NetStream.Unpublish.Success',如何在一段時間後再次調用close()? – SoftForge 2015-07-08 13:25:33