显示来自 Blob Javascript 的视频

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14317179/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 16:21:28  来源:igfitidea点击:

Display a video from a Blob Javascript

javascripthtmlvideoblob

提问by Antonin M.

I would like to display a video from a Javascript Blob/File object in the HTML5 video tag.

我想在 HTML5 视频标签中显示来自 Javascript Blob/File 对象的视频。

This code only works for small videos :

此代码仅适用于小视频:

var reader = new FileReader();
reader.onload = function(e) {
    document.getElementById("video").src=reader.result;
 }
reader.readAsDataURL(vid);

I cannot use this for big videos (> 10MB). Is there a solution to display a big video from a blob object in HTML 5?

我不能将它用于大视频(> 10MB)。是否有解决方案可以在 HTML 5 中显示来自 blob 对象的大视频?

回答by Antonin M.

I've found. It was so simple that I didnt even see it...

我找到了 太简单了,我什至都没看到……

function display(vid){

    var video = document.getElementById("video");
    video.src = window.URL.createObjectURL(vid);

}

回答by susan097

In some case blobObject.data should be provided in createObjectURL() method. See this simple trick:

在某些情况下,应在 createObjectURL() 方法中提供 blobObject.data。看看这个简单的技巧:

function playVideo(videoStream){ // as blob 

 var video = document.querySelector('video');

 var videoUrl=window.URL.createObjectURL(videoStream.data);// blob.data gives actual data

 video.src = videoUrl;
}