blob: c46dda9a8e0a5940e4e2b4ac37c044b7ca461aaf [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<title>media-webm-vorbis-partial</title>
<script src="../../media/media-source/media-source-loader.js"></script>
<script src="../../media/video-test.js"></script>
<script>
var loader;
var source;
var sourceBuffer;
function loaderPromise(loader) {
return new Promise((resolve, reject) => {
loader.onload = resolve;
loader.onerror = reject;
});
}
window.addEventListener('load', async event => {
try {
findMediaElement();
loader = new MediaSourceLoader('content/test-vorbis-manifest.json');
await loaderPromise(loader);
source = new MediaSource();
run('video.src = URL.createObjectURL(source)');
await waitFor(source, 'sourceopen');
waitFor(video, 'error').then(failTest);
run('sourceBuffer = source.addSourceBuffer(loader.type())');
run('sourceBuffer.appendBuffer(loader.initSegment())');
await waitFor(sourceBuffer, 'update');
consoleWrite('Divide the first media segment in two.');
run('partial1 = loader.mediaSegment(0).slice(0, loader.mediaSegment(0).byteLength / 2)');
run('partial2 = loader.mediaSegment(0).slice(loader.mediaSegment(0).byteLength / 2)');
consoleWrite('Append a partial media segment.')
run('sourceBuffer.appendBuffer(partial1)');
await waitFor(sourceBuffer, 'update');
testExpected('sourceBuffer.buffered.length', '1');
testExpected('sourceBuffer.buffered.end(0).toFixed(2)', '0.64', '==');
consoleWrite('Complete the partial media segment.')
run('sourceBuffer.appendBuffer(partial2)');
await waitFor(sourceBuffer, 'update');
testExpected('sourceBuffer.buffered.length', '1');
testExpected('sourceBuffer.buffered.end(0).toFixed(2)', '1.34', '==');
testExpected('sourceBuffer.buffered.end(0) == source.duration', true);
endTest();
} catch (e) {
failTest(`Caught exception: "${e}"`);
}
});
</script>
</head>
<body>
<video controls></video>
</body>
</html>