0
我使用MediaRecorder錄製麥克風。 Chrome中MediaRecorder的默認格式是video/webm。下面是簡單的例子:在Chrome上解碼Mediarecorder的音頻數據失敗
navigator.mediaDevices.getUserMedia({audio: true,video: false})
.then(function(stream) {
var recordedChunks = [];
var recorder = new MediaRecorder(stream);
recorder.start(10);
recorder.ondataavailable = function (event) {
if (event.data.size > 0) {
recordedChunks.push(event.data);
} else {
// ...
}
}
setTimeout(function(){
recorder.stop();
var blob = new Blob(recordedChunks, {
"type": recordedChunks[0].type
});
var blobUrl = URL.createObjectURL(blob);
var context = new AudioContext();
var request = new XMLHttpRequest();
request.open("GET", blobUrl, true);
request.responseType = "arraybuffer";
request.onload = function() {
context.decodeAudioData(
request.response,
function (buffer) {
if (!buffer) {
alert("buffer is empty!");
}
var dataArray = buffer.getChannelData(0);
//process channel data...
context.close();
},
function (error) {
alert(error);
}
);
};
request.send();
}, 3000);
})
.catch(function(error) {
console.log('error: ' + error);
});
此代碼是「未捕獲(在承諾)拋出:DOMException:無法解碼音頻數據」的錯誤特羅對context.decodeAudioData
只有鉻。
這裏有什麼問題,我該如何修復它在鉻?
這裏是工作在plunker例如:plunker