createObjectURL:使用 Blob 时在 Safari 中输入错误 [英] createObjectURL: Type Error in Safari when using Blob
问题描述
在 HTML 对象中,我无法播放由 video.js-record 库录制的视频.我检查了
player.recordedData
变量中返回的 Blob,并希望将其分配给文档中示例中提到的对象:
In HTML <video>
object, I cannot play a video recorded by the video.js-record library. I checked the Blob returned in the player.recordedData
variable and wanted to assign it to the object like mentioned in the example from the Documentation:
recordedVideo.src = createObjURL(this.player.recordedData);
它在此特定行上失败并出现错误:
It fails with an error on this specific line:
未处理的承诺拒绝:类型错误:类型错误
Unhandled Promise Rejection: TypeError: Type error
--
(我已经在使用这个函数检查 URL
和 webkitURL
的使用情况:
(I am already checking the use of URL
vs webkitURL
using this function:
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;
}
}
它似乎使用了正确的版本.)
and it seems to use the right version.)
推荐答案
查看 video.js-record 的文档,player.recordedData
不是 Blob(您需要传递给createObjectUrl
) 但一个 blob 段数组 - 这将匹配 TypeError
.
Looking at the document of video.js-record, player.recordedData
is not a Blob (what you would need to pass to createObjectUrl
) but an array of blob segments - this would match the TypeError
.
以下更改应该会有所帮助:
The following change should help:
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;
}
}
这篇关于createObjectURL:使用 Blob 时在 Safari 中输入错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!