Failed to execute 'createObjectURL' on 'URL':

后端 未结 8 1281
暗喜
暗喜 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:38

    The problem is that the keys provided in the loop do not refer to the index of the file.

    for (var i in this.files) {
        console.log(i);
    }
    

    The output of the above code is:

    0
    length
    item
    

    But what was expected was:

    0
    1
    2
    etc...
    

    Then the error occurs when the browser tries to execute, for example:

    window.URL.createObjectURL(this.files["length"])
    

    I suggest implementation based on the following code:

    var files = this.files;
    for (var i = 0; i < files.length; i++) {
        var file = files[i],
            src = (window.URL || window.webkitURL).createObjectURL(file);
        ...
    }
    

    I hope this can help someone.

    Greetings!

    0 讨论(0)
  • 2020-11-27 11:44

    Video with fall back:

    try {
      video.srcObject = mediaSource;
    } catch (error) {
      video.src = URL.createObjectURL(mediaSource);
    }
    video.play();
    

    From: https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/srcObject

    0 讨论(0)
提交回复
热议问题