<!DOCTYPE html><html><body><div id="video_player"><video width="400" id="main-video" controls><source src="video/video.mp4" type="video/mp4"></video></div></body></html>
Langkah 1 :
Membuat file javascript script.js :
const mainVideo = document.querySelector("#main-video");
// blob url
let mainVideoSources = mainVideo.querySelectorAll("source");
for (let i = 0; i < mainVideoSources.length; i++) {
let videoUrl = mainVideoSources[i].src;
blobUrl(mainVideoSources[i], videoUrl);
}
function blobUrl(video, videoUrl) {
let xhr = new XMLHttpRequest();
xhr.open("GET", videoUrl);
xhr.responseType = "arraybuffer";
xhr.onload = (e) => {
let blob = new Blob([xhr.response]);
let url = URL.createObjectURL(blob);
video.src = url;
};
xhr.send();
}
Kemudian sisipkan file script.js di dalam file index.html.
Hasilnya file source akan di convert kedalam bentuk blob jika di copy urlnya pada halaman browser tidak akan bisa memutar video tersebut.
Terima Kasih
Source : S-Tech04, w3schools
0 10 :
Post a Comment