4 <script src="/media-resources/video-test.js"></script>
5 <script src="/media/resources/media-source/webm/segment-info.js"></script>
6 <script src="webkitmediasource-util.js"></script>
8 var segmentHelper = new MediaSourceTest.SegmentHelper(WebMSegmentInfo.testWebM);
12 function onSourceOpen(event)
14 mediaSource.removeEventListener('webkitsourceopen', onSourceOpen);
16 // Add an initialization segment and multiple media segments.
17 segmentHelper.addSourceBuffer();
18 segmentHelper.appendInitSegment();
19 segmentHelper.appendAllMediaSegments();
21 // Appending all segments triggers a playing event;
22 // add a listener for that event.
23 video.addEventListener('playing', onPlaying);
26 function onPlaying(event)
28 consoleWrite("Original duration = " + mediaSource.duration.toFixed());
29 video.currentTime = seekTo;
31 // Changing video current-time triggers a seeked event.
32 // Add a listener to it.
33 video.addEventListener('seeked', onSeeked);
36 function onSeeked(event)
38 // Playtime should now be at 2 seconds.
39 // Set duration to < current playtime.
40 mediaSource.duration = newDuration;
41 testExpected("mediaSource.duration", newDuration, "==");
43 // Because the duration was set to be before the playback position,
44 // current playback position should now be the same as the new duration.
45 testExpected("mediaSource.duration", video.currentTime, "==");
46 consoleWrite("PASS: Media Source duration truncated and current time changed to = " + mediaSource.duration);
54 waitForEventAndFail('error');
56 mediaSource.addEventListener('webkitsourceopen', onSourceOpen);
58 segmentHelper.init(video, function (success)
61 failTest("Failed to load segment data");
65 MediaSourceTest.setSrcToMediaSourceTestURL(video);
70 <body onload="start()">
71 <video autoplay controls></video>
72 <p>Tests simple operations with duration attribute of MediaSource object.</p>