-
Notifications
You must be signed in to change notification settings - Fork 54
/
test_TruncatedDuration_mp4.html
59 lines (53 loc) · 2.18 KB
/
test_TruncatedDuration_mp4.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<!DOCTYPE HTML>
<html>
<head>
<title>MSE: truncating the media seeks to end of media and update buffered range</title>
<script 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">
// This test append data to a mediasource and then seek to half the duration
// of the video.
// We then shorten the video to 1/3rd of its original size.
// We ensure that the buffered range immediately reflect the truncation
// and that we've seeked to the new end of the media as per W3C spec and
// video.currentTime got updated.
SimpleTest.waitForExplicitFinish();
const round = n => Math.round(n * 1000) / 1000;
runWithMSE(async (ms, v) => {
await once(ms, "sourceopen");
const sb = ms.addSourceBuffer("video/mp4");
sb.appendBuffer(new Uint8Array(await fetchWithXHR("bipbop/bipbop2s.mp4")));
await once(sb, "updateend");
// mp4 metadata states 10s when we only have 1.6s worth of video.
sb.remove(sb.buffered.end(0), Infinity);
await once(sb, "updateend");
ms.duration = sb.buffered.end(0);
is(v.duration, ms.duration, "current time updated with mediasource duration");
v.currentTime = v.duration / 2;
is(v.currentTime, v.duration / 2, "current time was updated");
ok(v.seeking, "seeking is true");
await once(v, "seeked");
const duration = round(v.duration / 3);
is(sb.updating, false, "sourcebuffer isn't updating");
sb.remove(duration, Infinity);
await once(sb, "updateend");
ms.duration = duration;
// frames aren't truncated, so duration may be slightly more.
isfuzzy(v.duration, duration, 1 / 30, "element duration was updated");
sb.abort(); // this shouldn't abort updating the duration (bug 1130826).
ok(v.seeking, "seeking is true");
// test playback position was updated (bug 1130839).
is(v.currentTime, v.duration, "current time was updated");
is(sb.buffered.length, 1, "One buffered range");
// Truncated mediasource duration will cause the video element to seek.
await once(v, "seeking");
SimpleTest.finish();
});
</script>
</pre>
</body>
</html>