Skip to content

Instantly share code, notes, and snippets.

@jpmedley
Created October 20, 2017 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpmedley/f35015d0e0c8ad142e3e973a1955efa5 to your computer and use it in GitHub Desktop.
Save jpmedley/f35015d0e0c8ad142e3e973a1955efa5 to your computer and use it in GitHub Desktop.
// Example assumes that playbackRage == 1
function _appendPiece(piece, onQuotaError) {
try {
sourceBuffer.appendBuffer(piece);
}
catch e {
if (e.name !== 'QuotaExceededError') { throw e; }
onQuotaError(e);
}
}
function appendData(data) {
const pieces = new Uint8Array([data]);
pieces.forEach(piece => {
let retryCount = 3;
(function attemptAppend(piece) {
_appendPiece(piece, (e) => {
if (retryCount > 0) {
// Set a delay that lets most of the remaining buffered time go by.
let delay = 0.75 * (video.buffered.end(video.buffered.length - 1) - video.currentTime);
this.setTimeout(() => {
retryCount--;
attemptAppend(piece);
}, delay);
}
else {
throw(e);
}
})
})(piece)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment