const video = document.getElementById("video");
const progressBar = document.getElementById("progress");
var sourceBuffer, frameRate, arrayOfBytes, chunk, file, index = 0, videoInitialized = false,videoSeeked = false, isUserInteracting = false, segments = [], ms = new MediaSource();
video.src = window.URL.createObjectURL(ms);
ms.addEventListener('sourceopen', onMediaSourceOpen);
getData('output_dash.mpd');
function updatePromise() {
return new Promise(function(resolve, reject) {
sourceBuffer.addEventListener('updateend', function(e) {
console.log("updateend");
resolve();
}, true);
});
}
async function videoInit(bytes) {
chunk = bytes.slice(0, parseInt(segments[0].getAttribute("mediaRange").toString().split('-')[1]) + 1);
console.log("pausing video and appending single frame to buffer");
video.pause(); // same behavior if autoplay is disabled
if (sourceBuffer && sourceBuffer.updating) {
console.log("Buffer not ready");
} else if (chunk && sourceBuffer && !sourceBuffer.updating) {
let updateend = updatePromise();
sourceBuffer.appendBuffer(chunk);
await updateend;
console.log("setting currentTime now");
video.currentTime = index;
} else {
console.log("Something went wrong");
}
}
function onMediaSourceOpen() {
sourceBuffer = ms.addSourceBuffer('video/mp4; codecs="vp09.00.51.08.01.01.01.01.00"');
sourceBuffer.mode = 'sequence';
}
function getData(url) {
if (url !== "") {
url = "https://files.panomoments.com/" + url;
var xhr = new XMLHttpRequest(); // Set up xhr request
xhr.open("GET", url, true); // Open the request
xhr.responseType = "text"; // Set the type of response expected
xhr.send();
// Asynchronously wait for the data to return
xhr.onreadystatechange = function() {
if (xhr.readyState == xhr.DONE) {
var tempoutput = xhr.response;
var parser = new DOMParser(); // create a parser object
// Create an xml document from the .mpd file...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.