URL b.createObjectURL在Firefox中出现TypeError

问题描述 投票:2回答:1

我正在尝试从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;
    }
}

来自How to choose between `window.URL.createObjectURL()` and `window.webkitURL.createObjectURL()` based on browser,但不起作用

javascript firefox webrtc getusermedia
1个回答
1
投票

[在Firefox中,您可以直接将getUserMedia创建的媒体流赋予音频元素的“ mozSrcObject”属性。所以下面的代码应该工作:

audio_player.mozSrcObject = audio_blob;

您应考虑使用adapter.js文件来说明浏览器的差异。


0
投票

替换:

video.src = window.URL.createObjectURL(stream);

with:

video.srcObject = stream

来源:https://www.chromestatus.com/features/5618491470118912

© www.soinside.com 2019 - 2024. All rights reserved.