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 must be of the form: |
42 // media and waits for X seconds of playback or the ended event, at which point | 42 // "player.html?[tag]=[media_url](&loop=[true/false])". |
xhwang
2016/09/22 21:42:37
nit: typically we use [] for optional parameters.
derekjchow1
2016/09/22 23:00:01
Done.
| |
43 // the test seeks near the end of the file and resumes playback. Test completes | 43 // |
44 // when the second ended event occurs or an error event occurs at any time. | 44 // Plays the media and waits for X seconds of playback or the ended event, at |
45 // which point the test seeks near the end of the file and resumes playback. | |
46 // Test completes when the second ended event occurs or an error event occurs at | |
47 // any time. | |
48 // There is an optional loop query parameter which when set to true, will cause | |
49 // the created media element to loop. | |
45 function RunTest() { | 50 function RunTest() { |
46 var url_parts = window.location.href.split('?'); | 51 var url_parts = window.location.href.split('?'); |
47 if (url_parts.length != 2) | 52 if (url_parts.length != 2) |
48 return Failed(); | 53 return Failed(); |
49 | 54 |
50 var query_parts = url_parts[1].split('='); | 55 var tag = ''; |
51 if (query_parts.length != 2) | 56 var media_url = ''; |
57 var loop = false; | |
58 | |
59 var query_params = url_parts[1].split('&'); | |
60 for (var query_param in query_params) { | |
61 var query_parts = query_params[query_param].split('='); | |
62 if (query_parts.length != 2) { | |
63 return Failed(); | |
64 } | |
65 | |
66 if (query_parts[0] == 'audio' || query_parts[0] == 'video') { | |
67 tag = query_parts[0]; | |
68 media_url = query_parts[1]; | |
69 continue; | |
70 } | |
71 | |
72 if (query_parts[0] == 'loop') { | |
73 loop = (query_parts[1] == 'true'); | |
74 continue; | |
75 } | |
76 } | |
77 | |
78 if (tag != 'audio' && tag != 'video') { | |
52 return Failed(); | 79 return Failed(); |
53 | 80 } |
54 var tag = query_parts[0]; | |
55 var media_url = query_parts[1]; | |
56 if (tag != 'audio' && tag != 'video') | |
57 return Failed(); | |
58 | 81 |
59 // Create player and insert into DOM. | 82 // Create player and insert into DOM. |
60 player = document.createElement(tag); | 83 player = document.createElement(tag); |
61 player.controls = true; | 84 player.controls = true; |
62 document.getElementById('player_container').appendChild(player); | 85 document.getElementById('player_container').appendChild(player); |
63 | 86 |
64 player.addEventListener('loadedmetadata', function(e) { | 87 player.addEventListener('loadedmetadata', function(e) { |
65 document.title = '' + player.videoWidth + ' ' + player.videoHeight; | 88 document.title = '' + player.videoWidth + ' ' + player.videoHeight; |
66 }); | 89 }); |
67 | 90 |
68 // Transition to the seek test after X seconds of playback or when the ended | 91 // Transition to the seek test after X seconds of playback or when the ended |
69 // event occurs, whichever happens first. | 92 // event occurs, whichever happens first. |
70 player.addEventListener('ended', SeekTestStep, false); | 93 player.addEventListener('ended', SeekTestStep, false); |
71 player.addEventListener('timeupdate', SeekTestTimeoutSetup, false); | 94 player.addEventListener('timeupdate', SeekTestTimeoutSetup, false); |
72 | 95 |
73 // Ensure we percolate up any error events. | 96 // Ensure we percolate up any error events. |
74 InstallTitleEventHandler(player, 'error'); | 97 InstallTitleEventHandler(player, 'error'); |
75 | 98 |
76 // Starts the player. | 99 // Starts the player. |
100 player.loop = loop; | |
77 player.src = media_url; | 101 player.src = media_url; |
78 player.play(); | 102 player.play(); |
79 } | 103 } |
80 </script> | 104 </script> |
81 </html> | 105 </html> |
OLD | NEW |