3 <title>Test media source config changes.
</title>
5 <body onload=
"runTest();">
6 <video controls
></video>
7 <script src=
"media_utils.js" type=
"text/javascript"></script>
8 <script src=
"media_source_utils.js" type=
"text/javascript"></script>
9 <script src=
"encrypted_media_utils.js" type=
"text/javascript"></script>
10 <script type=
"text/javascript">
11 var runEncrypted
= QueryString
.runencrypted
== 1;
12 var video
= document
.querySelector('video');
13 var mediaType
= 'video/webm; codecs="vorbis, vp8"';
15 var MEDIA_1
= 'bear-320x240.webm';
16 var MEDIA_2
= 'bear-640x360.webm';
18 MEDIA_1
= 'bear-320x240-av-enc_av.webm';
19 MEDIA_2
= 'bear-640x360-av-enc_av.webm';
22 var MEDIA_1_WIDTH
= 320;
23 var MEDIA_1_HEIGHT
= 240;
25 var MEDIA_2_WIDTH
= 640;
26 var MEDIA_2_HEIGHT
= 360;
27 var MEDIA_2_LENGTH
= 2.75;
29 // The time in secs to append the second media source.
31 // DELTA is the time after APPEND_TIME where the second video dimensions
32 // are guaranteed to take effect.
34 // Append MEDIA_2 source at APPEND_TIME, so expected total duration is:
35 var TOTAL_DURATION
= APPEND_TIME
+ MEDIA_2_LENGTH
;
37 function appendNextSource(mediaSource
) {
38 console
.log('Appending next media source at ' + APPEND_TIME
+ 'sec.');
39 var xhr
= new XMLHttpRequest();
40 xhr
.open("GET", MEDIA_2
);
41 xhr
.responseType
= 'arraybuffer';
42 xhr
.addEventListener('load', function(e
) {
43 var onUpdateEnd = function(e
) {
44 console
.log('Second buffer append ended.');
45 srcBuffer
.removeEventListener('updateend', onUpdateEnd
);
46 mediaSource
.endOfStream();
47 if (!mediaSource
.duration
||
48 Math
.abs(mediaSource
.duration
- TOTAL_DURATION
) > DELTA
) {
49 failTest('Unexpected mediaSource.duration = ' +
50 mediaSource
.duration
+ ', expected duration = ' +
56 console
.log('Appending next media source at ' + APPEND_TIME
+ 'sec.');
57 var srcBuffer
= mediaSource
.sourceBuffers
[0];
58 srcBuffer
.addEventListener('updateend', onUpdateEnd
);
59 srcBuffer
.timestampOffset
= APPEND_TIME
;
60 srcBuffer
.appendBuffer(new Uint8Array(e
.target
.response
));
65 function onTimeUpdate() {
67 //checkVideoProperties();
69 // Seek to APPEND_TIME because after a seek a timeUpdate event is fired
70 // before video width and height properties get updated.
71 if (video
.currentTime
< APPEND_TIME
- DELTA
) {
72 // Seek to save test execution time (about 1 secs) and to test seek
73 // on the first buffer.
74 video
.currentTime
= APPEND_TIME
- DELTA
;
75 } else if (video
.currentTime
> APPEND_TIME
+ DELTA
) {
76 // Check video duration here to guarantee that second segment has been
77 // appended and video total duration is updated.
78 // Video duration is a float value so we check it within a range.
79 if (!video
.duration
||
80 Math
.abs(video
.duration
- TOTAL_DURATION
) > DELTA
) {
81 failTest('Unexpected video.duration = ' + video
.duration
+
82 ', expected duration = ' + TOTAL_DURATION
);
86 video
.removeEventListener('timeupdate', onTimeUpdate
);
87 video
.removeEventListener('ended', failTest
);
88 installTitleEventHandler(video
, 'ended');
89 // Seek to save test execution time and to test seek on second buffer.
90 video
.currentTime
= APPEND_TIME
+ MEDIA_2_LENGTH
* 0.9;
94 function checkVideoProperties() {
95 if (video
.currentTime
<= APPEND_TIME
) {
96 if (video
.videoWidth
!= MEDIA_1_WIDTH
||
97 video
.videoHeight
!= MEDIA_1_HEIGHT
) {
99 failTest('Unexpected dimensions for first video segment.');
102 } else if (video
.currentTime
>= APPEND_TIME
+ DELTA
) {
103 if (video
.videoWidth
!= MEDIA_2_WIDTH
||
104 video
.videoHeight
!= MEDIA_2_HEIGHT
) {
105 logVideoDimensions();
106 failTest('Unexpected dimensions for second video segment.');
112 function logVideoDimensions() {
113 console
.log('video.currentTime = ' + video
.currentTime
+
114 ', video dimensions = ' + video
.videoWidth
+ 'x' +
115 video
.videoHeight
+ '.');
119 video
.addEventListener('timeupdate', onTimeUpdate
);
120 video
.addEventListener('ended', failTest
);
122 loadEncryptedMedia(video
, MEDIA_1
, keySystem
, KEY
, true,
125 var mediaSource
= loadMediaSource(MEDIA_1
, mediaType
,
127 video
.src
= window
.URL
.createObjectURL(mediaSource
);