Ton*_*niq 6 base64 html5-video
我正在尝试播放使用 base64 编码的 html5 视频,但它不起作用。它无需编码即可工作。问题是什么?
var s = 'http://clips.vorwaerts-gmbh.de/VfE_html5.mp4';
var video = document.createElement('video');
document.body.appendChild(video);
video.src = "data:video/mp4;base64," + btoa(s);//not working
//video.src = s;//works
video.autoplay = true;
video.controls = true;Run Code Online (Sandbox Code Playgroud)
小智 1
function displayVideo (base64){
var video = document.getElementById("video");
var binaryString = atob(base64String);
var blob = new Blob([binaryString], {type: "video/mp4"}); // Replace "video/mp4" with the type MIME of your video
video.srcObject = window.URL.createObjectURL(blob);
}
Run Code Online (Sandbox Code Playgroud)