[英]Converting .mp4 link to BLOB in JavaScript
Currently I'm trying convert a external .mp4 file (URL) to blob object using Javascript. 目前,我正在尝试使用Javascript将外部.mp4文件(URL)转换为blob对象。 Here is my script:
这是我的脚本:
<!DOCTYPE html>
<html>
<body>
<video controls="" preload="auto" id="_video"></video>
</body>
</html>
<script>
function createObjectURL(object) {
return (window.URL) ? window.URL.createObjectURL(object) : window.webkitURL.createObjectURL(object);
}
function display(videoStream){
var video = document.querySelector('_video');
var videoUrl=createObjectURL(videoStream);
video.src = videoUrl;
}
display('http://vjs.zencdn.net/v/oceans.mp4');
</script>
But I'm getting: 但我得到:
Failed to execute
'createObjectURL' on 'URL': No function was found that matched the signature provided.
无法
'createObjectURL' on 'URL': No function was found that matched the signature provided.
执行'createObjectURL' on 'URL': No function was found that matched the signature provided.
Jsfiddle: http://jsfiddle.net/xyzr67Lu/ Jsfiddle: http : //jsfiddle.net/xyzr67Lu/
You do not need to create a Blob object, you can use the url directly: 您不需要创建Blob对象,可以直接使用url:
<!DOCTYPE html>
<html>
<body>
<video controls="" preload="auto" id="_video"></video>
</body>
</html>
<script>
function display(videoStream){
var video = document.getElementById('_video');
video.src = videoStream;
}
display('http://vjs.zencdn.net/v/oceans.mp4');
</script>
If you really want to create a Blob, then you can achieve this by downloading the video first, although the user experience will suffer from this: 如果您确实想创建一个Blob,则可以通过首先下载视频来实现,尽管用户体验会因此受到影响:
<!DOCTYPE html>
<html>
<body>
<video controls="" preload="auto" id="_video"></video>
</body>
</html>
<script>
function createObjectURL(object) {
return (window.URL) ? window.URL.createObjectURL(object) : window.webkitURL.createObjectURL(object);
}
async function display(videoStream){
var video = document.getElementById('_video');
let blob = await fetch(videoStream).then(r => r.blob());
var videoUrl=createObjectURL(blob);
video.src = videoUrl;
}
display('http://vjs.zencdn.net/v/oceans.mp4');
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.