【问题标题】:createObjectURL: Type Error in Safari when using BlobcreateObjectURL:使用 Blob 时在 Safari 中键入错误
【发布时间】:2020-01-24 14:41:42
【问题描述】:

在 HTML <video> 对象中,我无法播放由 video.js-record 库录制的视频。我检查了在 player.recordedData 变量中返回的 Blob,并希望将其分配给文档中示例中提到的对象:

recordedVideo.src = createObjURL(this.player.recordedData);

失败并在此特定行出现错误:

未处理的承诺拒绝:TypeError:类型错误

--

(我已经在使用此功能检查URLwebkitURL 的使用情况:

function createObjURL ( file ) {
    if ( window.webkitURL ) {
        return window.webkitURL.createObjectURL( file );
    } else if ( window.URL && window.URL.createObjectURL ) {
        return window.URL.createObjectURL( file );
    } else {
        return null;
    }
}

而且它似乎使用了正确的版本。)

【问题讨论】:

    标签: javascript webrtc blob video.js createobjecturl


    【解决方案1】:

    查看 video.js-record 的文档,player.recordedData 不是 Blob(您需要传递给 createObjectUrl),而是一个 Blob 段数组 - 这将与 TypeError 匹配。

    以下更改应该会有所帮助:

    function createObjURL ( blobPieces ) {
        var blob = new Blob(blobPieces, { type: 'video/webm' });
        if ( window.webkitURL ) {
            return window.webkitURL.createObjectURL( blob );
        } else if ( window.URL && window.URL.createObjectURL ) {
            return window.URL.createObjectURL( blob );
        } else {
            return null;
        }
    }
    

    【讨论】:

    • 不幸的是没有帮助。 player.recordedData 已经返回一个 Blob。这将是它的 console.log:Blob { lastModified: 1580220847318, lastModifiedDate: Date Tue Jan 28 2020 15:14:07 GMT+0100, name: "1580220847318.webm", size: 362155, type: "video/webm" }
    猜你喜欢
    • 2022-10-07
    • 2017-12-23
    • 2016-09-06
    • 1970-01-01
    • 2022-10-24
    • 2017-12-26
    • 2016-04-16
    • 2021-09-23
    • 2023-03-16
    相关资源
    最近更新 更多