0
我創建了一個腳本,允許我從畫布上記錄一個id爲「imacanvas」的視頻。但問題是沒有創建斑點。我認爲問題在於函數handleDataAvailable未被執行。但我不知道爲什麼?MediaRecorder沒有定義斑點
感謝您的幫助:)
var recordedBlobs;
var recorder;
var stream;
function handleDataAvailable(event) {
console.log("0");
if (event.data && event.data.size > 0) {
recordedBlobs.push(event.data);
console.log("1");
}
}
function startRecord(){
recordedBlobs = [];
var canvas = document.getElementById('imacanvas');
stream = canvas.captureStream(60);
try {
recorder = new MediaRecorder(stream);
} catch (e) {
console.error('Exception while creating MediaRecorder: ' + e);
alert('Exception while creating MediaRecorder: '
+ e + '. mimeType: ' + options.mimeType);
return;
}
recorder.ondataavailable = handleDataAvailable;
recorder.start(10);
}
function stopRecord() {
recorder.stop();
console.log('Recorded Blobs: ', recordedBlobs);
}
function download() {
var blob = new Blob(recordedBlobs, {type: 'video/webm'});
var url = window.URL.createObjectURL(blob);
var a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = 'test.webm';
document.body.appendChild(a);
a.click();
setTimeout(function() {
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, 100);
}