我正在尝试从getUserMedia
创建的音频Blob中创建对象URL。该代码可在Chrome中运行,但Firefox中存在问题。
错误:
当我呼叫stopAudioRecorder()
时,它停在audio_player.src = URL.createObjectURL(audio_blob);
TypeError: Argument 1 is not valid for any of the 2-argument overloads of URL.createObjectURL.
代码:
var stopAudioRecorder = function(audio_recorder) {
var audio_blob, audio_player, new_recording, save_button;
audio_recorder.stopRecording();
audio_blob = audio_recorder.getBlob();
audio_player = document.createElement("audio");
audio_player.src = URL.createObjectURL(audio_blob);
audio_player.controls = true;
audio_player.play();
$('#new_recording').appendChild(audio_player);
recording = false;
return ($("#record_button")).text("Start recording");
};
我试图通过添加包装器功能来提供一些跨浏览器的兼容性
function createObjectURL ( file ) {
if ( window.webkitURL ) {
return window.webkitURL.createObjectURL( file );
} else if ( window.URL && window.URL.createObjectURL ) {
return window.URL.createObjectURL( file );
} else {
return null;
}
}
[在Firefox中,您可以直接将getUserMedia创建的媒体流赋予音频元素的“ mozSrcObject”属性。所以下面的代码应该工作:
audio_player.mozSrcObject = audio_blob;
您应考虑使用adapter.js文件来说明浏览器的差异。
替换:
video.src = window.URL.createObjectURL(stream);
with:
video.srcObject = stream