MSE Safari SetInterval Seeked

by dustinkerstein

HTML

<video></video>

CSS

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #000;
}

video {
  margin: 0;
  width: 100%;
  height: 100%;
}

JavaScript

var sourceBuffer;
var frameRate;
var index = 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);

video.addEventListener('seeked', (event) => {
  seeked++;
  console.log('seeked: ' + seeked + " count: " + count);
});

getData('uhd_dash.mpd');

function render() {
  if (video.readyState === video.HAVE_ENOUGH_DATA) {
    index = (index + 1) % segments.length;
    nextSegment(index);
  }

}

function videoInit(initBytes) {
  videoBits = initBytes;
  chunk = initBytes.slice(0, parseInt(segments[0].getAttribute("mediaRange").toString().split('-')[1]) + 1);
  appendToBuffer(chunk);
  setInterval(render, 5);
}

function onMediaSourceOpen() {
  sourceBuffer = ms.addSourceBuffer('audio/mpeg'); 
  sourceBuffer.mode = 'sequence';
}

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);
  }

}

var count = 0;
var seeked = 0;
function appendToBuffer(videoChunk) {
  if (sourceBuffer.updating) {
    console.log("Buffer not ready");
  }
  if (videoChunk && !sourceBuffer.updating) {
    //video.currentTime = count;
    video.fastSeek(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 return
    xhr.onreadystatechange = function() {
      if (xhr.readyState == xhr.DONE) {
        var tempoutput = xhr.response;
        var parser = new DOMParser(); //  create...