Created
October 20, 2017 20:02
-
-
Save jpmedley/f35015d0e0c8ad142e3e973a1955efa5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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