Failed to execute 'createObjectURL' on 'URL':

后端 未结 8 1327
暗喜
暗喜 2020-11-27 10:52

Display Below error in Safari.

Failed to execute \'createObjectURL\' on \'URL\': No function was found that matched the signature provided.

8条回答
  •  春和景丽
    2020-11-27 11:20

    UPDATE

    Consider avoiding createObjectURL() method, while browsers are disabling support for it. Just attach MediaStream object directly to the srcObject property of HTMLMediaElement e.g. element.

    const mediaStream = new MediaStream();
    const video = document.getElementById('video-player');
    video.srcObject = mediaStream;
    

    However, if you need to work with MediaSource, Blob or File, you have to create a URL with URL.createObjectURL() and assign it to HTMLMediaElement.src.

    Read more details here: https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/srcObject


    Older Answer

    I experienced same error, when I passed to createObjectURL raw data:

    window.URL.createObjectURL(data)
    

    It has to be Blob, File or MediaSource object, not data itself. This worked for me:

    var binaryData = [];
    binaryData.push(data);
    window.URL.createObjectURL(new Blob(binaryData, {type: "application/zip"}))
    

    Check also the MDN for more info: https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL

提交回复
热议问题