var sourceBuffer;
var frameRate;
var index = 0;
var count = 0;
var segments = [];
var ms = new MediaSource();
var videoBits, arrayOfBytes, chunk, file;
var video = document.querySelector('video');
video.src = window.URL.createObjectURL(ms);
ms.addEventListener('sourceopen', onMediaSourceOpen);
function animate() {
window.requestAnimationFrame(render);
}
function render() {
window.requestAnimationFrame(render);
if (video.readyState >= 3) {
nextSegment(index);
}
index = (index + 1) % (segments.length-1);
}
function videoInit(initBytes) {
videoBits = initBytes;
chunk = initBytes.slice(0, parseInt(segments[0].getAttribute("mediaRange").toString().split('-')[1]) + 1);
sourceBuffer.appendBuffer(chunk);
animate();
}
function onMediaSourceOpen() {
sourceBuffer = ms.addSourceBuffer('audio/mpeg'); // Workaround by tricking Safari into setting m_shouldGenerateTimestamps (https://github.com/WebKit/webkit/blob/29271ffbec500cd9c92050fcc0e613adffd0ce6a/Source/WebCore/Modules/mediasource/SourceBuffer.cpp)
sourceBuffer.mode = 'sequence';
getData('hd_dash.mpd'); // 100% I-Frames
}
function nextSegment(index) {
if (index < segments.length) {
arrayOfBytes = segments[index].getAttribute("mediaRange").toString().split('-');
chunk = videoBits.slice(arrayOfBytes[0], parseInt(arrayOfBytes[1]) + 1);
appendToBuffer(chunk);
}
}
function appendToBuffer(videoChunk) {
if (sourceBuffer.updating) {
console.log("Buffer not ready");
}
if (videoChunk && !sourceBuffer.updating) {
video.currentTime = count;
sourceBuffer.timestampOffset = count;
sourceBuffer.appendBuffer(videoChunk);
count++;
}
}
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...
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.