blob: 2d62a811c435cd32e2ceb142fb2e75681e30f025 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<title>media-source-webm</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 {
window.audio = document.querySelector('audio');
loader = new MediaSourceLoader('content/test-48kHz-vorbis-manifest.json');
await loaderPromise(loader);
source = new MediaSource();
run('audio.src = URL.createObjectURL(source)');
await waitFor(source, 'sourceopen');
waitFor(audio, 'error').then(failTest);
run('source.duration = loader.duration()');
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, 280)');
run('partial2 = loader.mediaSegment(0).slice(280)');
consoleWrite('Append a partial media segment.')
run('sourceBuffer.appendBuffer(partial1)');
await waitFor(sourceBuffer, 'update');
consoleWrite('Complete the partial media segment.')
run('sourceBuffer.appendBuffer(partial2)');
await waitFor(sourceBuffer, 'update');
testExpected('sourceBuffer.buffered.length', '1');
testExpected('sourceBuffer.buffered.end(0)', '1', '>');
endTest();
} catch (e) {
failTest(`Caught exception: "${e}"`);
}
});
</script>
</head>
<body>
<audio controls></video>
</body>
</html>