Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / media / test / data / player.html
blobfa50d731e1a3610e1f9db825f5cb6f104bb072df
1 <html>
2 <body onload="RunTest();">
3 <div id="player_container"></div>
4 </body>
6 <script type="text/javascript">
7 // <audio> or <video> player element.
8 var player;
10 // Listen for |event| from |element|, set document.title = |event| upon event.
11 function InstallTitleEventHandler(element, event) {
12 element.addEventListener(event, function(e) {
13 document.title = event.toUpperCase();
14 }, false);
17 function Failed() {
18 document.title = 'FAILED';
19 return false;
22 function SeekTestStep(e) {
23 player.removeEventListener('ended', SeekTestStep, false);
25 // Test completes on the next ended event.
26 InstallTitleEventHandler(player, 'ended');
28 player.currentTime = 0.9 * player.duration;
29 player.play();
32 function SeekTestTimeoutSetup() {
33 if (player.currentTime < 2)
34 return;
36 player.removeEventListener('timeupdate', SeekTestTimeoutSetup, false);
37 SeekTestStep();
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
42 // media and waits for X seconds of playback or the ended event, at which point
43 // the test seeks near the end of the file and resumes playback. Test completes
44 // when the second ended event occurs or an error event occurs at any time.
45 function RunTest() {
46 var url_parts = window.location.href.split('?');
47 if (url_parts.length != 2)
48 return Failed();
50 var query_parts = url_parts[1].split('=');
51 if (query_parts.length != 2)
52 return Failed();
54 var tag = query_parts[0];
55 var media_url = query_parts[1];
56 if (tag != 'audio' && tag != 'video')
57 return Failed();
59 // Create player and insert into DOM.
60 player = document.createElement(tag);
61 player.controls = true;
62 document.getElementById('player_container').appendChild(player);
64 player.addEventListener('loadedmetadata', function(e) {
65 document.title = '' + player.videoWidth + ' ' + player.videoHeight;
66 });
68 // Transition to the seek test after X seconds of playback or when the ended
69 // event occurs, whichever happens first.
70 player.addEventListener('ended', SeekTestStep, false);
71 player.addEventListener('timeupdate', SeekTestTimeoutSetup, false);
73 // Ensure we percolate up any error events.
74 InstallTitleEventHandler(player, 'error');
76 // Starts the player.
77 player.src = media_url;
78 player.play();
80 </script>
81 </html>