我使用下面的javascript代码创建blob网址。如果视频大小更像(500mb),则需要花费大量时间。
请帮我为大型视频创建blob网址
如果我们能看到Youtube,即使视频播放速度非常快,但BLOB网址
<html>
<head>
<title>Blob URL</title>
</head>
<body>
<video controls="" preload="auto" id="_video"></video>
<script>
var xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
xhr.onload = function() {
var reader = new FileReader();
reader.onloadend = function() {
//console.log(atob(reader.result.slice(reader.result.indexOf(',') + 1)));
var byteCharacters = atob(reader.result.slice(reader.result.indexOf(',') + 1));
var byteNumbers = new Array(byteCharacters.length);
for (var i = 0; i < byteCharacters.length; i++) {
byteNumbers[i] = byteCharacters.charCodeAt(i);
//console.log(i);
}
var byteArray = new Uint8Array(byteNumbers);
var blob = new Blob([byteArray], {type: 'video/mp4'});
var url = URL.createObjectURL(blob);
document.getElementById('_video').src = url;
}
reader.readAsDataURL(xhr.response);
};
xhr.open('GET', 'domain.com/738-360p.mp4',true);
xhr.send();
</script>
</body>
</html>