OLD | NEW |
---|---|
1 <html> | 1 <html> |
2 <body onload="RunTest();"> | 2 <body onload="RunTest();"> |
3 <div id="player_container"></div> | 3 <div id="player_container"></div> |
4 </body> | 4 </body> |
5 | 5 |
6 <script type="text/javascript"> | 6 <script type="text/javascript"> |
7 // <audio> or <video> player element. | 7 // <audio> or <video> player element. |
8 var player; | 8 var player; |
9 | 9 |
10 // Listen for |event| from |element|, set document.title = |event| upon event. | 10 // Listen for |event| from |element|, set document.title = |event| upon event. |
(...skipping 20 matching lines...) Expand all Loading... | |
31 | 31 |
32 function SeekTestTimeoutSetup() { | 32 function SeekTestTimeoutSetup() { |
33 if (player.currentTime < 2) | 33 if (player.currentTime < 2) |
34 return; | 34 return; |
35 | 35 |
36 player.removeEventListener('timeupdate', SeekTestTimeoutSetup, false); | 36 player.removeEventListener('timeupdate', SeekTestTimeoutSetup, false); |
37 SeekTestStep(); | 37 SeekTestStep(); |
38 } | 38 } |
39 | 39 |
40 // Uses URL query parameters to create an audio or video element using a given | 40 // Uses URL query parameters to create an audio or video element using a given |
41 // source. URL must be of the form "player.html?[tag]=[media_url]". Plays the | 41 // source. URL format must be "player.html?[tag]=[media_url](&extra_params)". |
42 // media and waits for X seconds of playback or the ended event, at which point | 42 // Plays the media and waits for X seconds of playback or the ended event, at |
43 // the test seeks near the end of the file and resumes playback. Test completes | 43 // which point the test seeks near the end of the file and resumes playback. |
44 // when the second ended event occurs or an error event occurs at any time. | 44 // Test completes when the second ended event occurs or an error event occurs at |
45 // any time. | |
46 // There is an optional loop query parameter which when set to true, will cause | |
47 // the created audio element to loop. | |
xhwang
2016/09/21 22:37:41
Can you actually expand the "extra_params" since w
derekjchow1
2016/09/22 20:32:43
Added loop in explicitly and changed the "audio" e
| |
45 function RunTest() { | 48 function RunTest() { |
46 var url_parts = window.location.href.split('?'); | 49 var url_parts = window.location.href.split('?'); |
47 if (url_parts.length != 2) | 50 if (url_parts.length != 2) |
48 return Failed(); | 51 return Failed(); |
49 | 52 |
50 var query_parts = url_parts[1].split('='); | 53 var tag = ''; |
51 if (query_parts.length != 2) | 54 var media_url = ''; |
55 var loop = false; | |
56 | |
57 var query_params = url_parts[1].split('&'); | |
58 for (var query_param in query_params) { | |
59 var query_parts = query_params[query_param].split('='); | |
60 if (query_parts.length != 2) { | |
61 return Failed(); | |
62 } | |
63 | |
64 if (query_parts[0] == 'audio' || query_parts[0] == 'video') { | |
65 tag = query_parts[0]; | |
66 media_url = query_parts[1]; | |
67 continue; | |
68 } | |
69 | |
70 if (query_parts[0] == 'loop') { | |
71 loop = (query_parts[1] == 'true'); | |
72 continue; | |
73 } | |
74 } | |
75 | |
76 if (tag != 'audio' && tag != 'video') { | |
52 return Failed(); | 77 return Failed(); |
53 | 78 } |
54 var tag = query_parts[0]; | |
55 var media_url = query_parts[1]; | |
56 if (tag != 'audio' && tag != 'video') | |
57 return Failed(); | |
58 | 79 |
59 // Create player and insert into DOM. | 80 // Create player and insert into DOM. |
60 player = document.createElement(tag); | 81 player = document.createElement(tag); |
61 player.controls = true; | 82 player.controls = true; |
62 document.getElementById('player_container').appendChild(player); | 83 document.getElementById('player_container').appendChild(player); |
63 | 84 |
64 player.addEventListener('loadedmetadata', function(e) { | 85 player.addEventListener('loadedmetadata', function(e) { |
65 document.title = '' + player.videoWidth + ' ' + player.videoHeight; | 86 document.title = '' + player.videoWidth + ' ' + player.videoHeight; |
66 }); | 87 }); |
67 | 88 |
68 // Transition to the seek test after X seconds of playback or when the ended | 89 // Transition to the seek test after X seconds of playback or when the ended |
69 // event occurs, whichever happens first. | 90 // event occurs, whichever happens first. |
70 player.addEventListener('ended', SeekTestStep, false); | 91 player.addEventListener('ended', SeekTestStep, false); |
71 player.addEventListener('timeupdate', SeekTestTimeoutSetup, false); | 92 player.addEventListener('timeupdate', SeekTestTimeoutSetup, false); |
72 | 93 |
73 // Ensure we percolate up any error events. | 94 // Ensure we percolate up any error events. |
74 InstallTitleEventHandler(player, 'error'); | 95 InstallTitleEventHandler(player, 'error'); |
75 | 96 |
76 // Starts the player. | 97 // Starts the player. |
98 player.loop = loop; | |
77 player.src = media_url; | 99 player.src = media_url; |
78 player.play(); | 100 player.play(); |
79 } | 101 } |
80 </script> | 102 </script> |
81 </html> | 103 </html> |
OLD | NEW |