gecko-dev/dom/media/mediasource/test/test_DurationUpdated.html

60 строки
2.0 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/webm");
fetchWithXHR("seek.webm", function (arrayBuffer) {
sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 318));
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, 318));
} else if (updateCount == 3) {
// this will not fire durationchange as new duration == old duration
ms.endOfStream();
}
});
});
});
ms.addEventListener("sourceended", function () {
// XXX: Duration should be exactly 4.0, see bug 1065207.
is(durationChangeCount, 2, "durationchange not fired as many times as expected");
ok(Math.abs(v.duration - 4) <= 0.002, "Video has correct duration");
SimpleTest.finish();
});
});
</script>
</pre>
</body>
</html>