HTML5:从存储的二进制字符串播放视频 [英] HTML5: Play video from stored binary string
问题描述
我正在尝试使用FileReader.readAsBinaryString(Blob | File)将视频文件的内容作为二进制字符串读取,如示例 http://www.html5rocks.com/en/tutorials/file/dndfiles/#toc-reading-files 然后存储播放视频。
I am trying to read the contents of a video file as a binary string using the FileReader.readAsBinaryString(Blob|File) as shown in the example http://www.html5rocks.com/en/tutorials/file/dndfiles/#toc-reading-files and then store and play the video.
我尝试使用下面的(使用webm视频文件),但获得不支持视频格式或MIME类型。
I tried it using the below (with a webm video file),but get a "Video format or MIME type not supported."
function readBlob (file, startByte, endByte, callback) {
console.log('readBlob():', file, startByte, endByte);
var reader = new FileReader();
reader.onloadend = function (evt) {
if (evt.target.readyState == FileReader.DONE) {
callback(evt.target.result);
var player = document.getElementById('player');
player.src = "data:video/webm;base64,"+evt.target.result;
player.load();
player.play();
}
}
var blob = file.slice(startByte, endByte);
reader.readAsBinaryString(blob);
}
有谁知道是否可以阅读视频文件(一个支持者)正在使用的浏览器)作为二进制字符串并在浏览器HTML5视频播放器中播放?
Does anyone know if it is possible to read a video file (one supported by the browser being used) as a binary string and play it in the browser HTML5 video player?
TIA
推荐答案
您的问题可能出在 player.src
player.src = "data:video/webm;base64,"+evt.target.result;
预计数据在base64中,但你给它一个二进制字符串。
It is expecting the data to be in base64 but you're giving it a binary string.
尝试使用 btoa将其编码为base64
player.src = "data:video/webm;base64,"+btoa(evt.target.result);
这篇关于HTML5:从存储的二进制字符串播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!