我正在使用MediaStreamRecorder,它跟在MediaRecorder API之後用於錄製跨瀏覽器的音頻和視頻流。MediaStreamRecorder在瀏覽器窗口最小化時停止錄製
我面臨的問題是,只要瀏覽器窗口最小化,MediaStreamRecorder
就會停止觸發其ondataavailable
事件。一旦你最小化它停止觸發ondataavailable
事件,即使我回到相同的窗口,也不會觸發,除非或直到我停止錄製並重新啓動它。
它不會在瀏覽器控制檯中給出任何例外。一切正常,直到你最小化瀏覽器窗口。一旦你這樣做了,它會停止執行在ondataavailable
事件上執行的函數中的代碼。
var ws;
function start() {
ws = new WebSocket("wss://xyz/");
ws.onopen = function() {
console.log("WebSocket has been opened!");
};
ws.onmessage = function (message) {
console.log("A messsage is received from WebSocket Server.", message);
};
ws.onclose = function (e) {
console.log('WebSocket is closed. Reconnection will be attempted in 5 second.', e.reason);
setTimeout(function() {
start();
}, 5000);
};
ws.onerror = function (err) {
console.error('WebSocket encountered an error: ', err.message, 'Closing WebSocket');
ws.close();
};
}
start();
function startRecording(localStream, remoteStream) {
if (localStream != null && remoteStream != null) {
multiStreamRecorder = new MultiStreamRecorder([localStream, remoteStream], "video/webm");
multiStreamRecorder.mimeType = "video/webm";
multiStreamRecorder.ondataavailable = function (blob) {
console.log("sending blob to websocket server");
ws.send(blob);
};
multiStreamRecorder.start(1500);
}
else{
console.error("One or more streams are null.");
}
}