tenfourfox/dom/media/mediasource/test/test_DurationUpdated_mp4.html
Cameron Kaiser c9b2922b70 hello FPR
2017-04-19 00:56:45 -07:00

61 lines
2.1 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>MSE: append data and check that mediasource duration got updated</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="mediasource.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
var updateCount = 0;
var durationChangeCount = 0;
runWithMSE(function (ms, v) {
ms.addEventListener("sourceopen", function () {
var sb = ms.addSourceBuffer("video/mp4");
fetchWithXHR("bipbop/bipbop2s.mp4", function (arrayBuffer) {
sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 1395));
sb.addEventListener("updateend", function () {
updateCount++;
if (updateCount == 1) {
v.addEventListener("loadedmetadata", function () {
v.addEventListener("durationchange", function () {
durationChangeCount++;
});
// Set mediasource duration to 0, so future appendBuffer
// will update the mediasource duration
// setting ms.duration will fire updatestart/update/updateend
// event as per w3c spec followed by a durationchange
ms.duration = 0;
});
} else if (updateCount == 2) {
// will fire updatestart/update/updateend
// and a durationchange
sb.appendBuffer(new Uint8Array(arrayBuffer, 1395));
} else if (updateCount == 3) {
// this will not fire durationchange as new duration == old duration
ms.endOfStream();
}
});
});
});
ms.addEventListener("sourceended", function () {
is(durationChangeCount, 2, "durationchange not fired as many times as expected");
// The bipbop video doesn't start at 0. The old MSE code adjust the
// timestamps and ignore the audio track. The new one doesn't.
isfuzzy(v.duration, 1.696, 0.166, "Video has correct duration");
SimpleTest.finish();
});
});
</script>
</pre>
</body>
</html>