test_wav_ended2.html (1451B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Wave Media test: ended and replaying</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 7 </head> 8 <body> 9 <!-- try with autoplay and no v.play in starttest, also with both --> 10 <pre id="test"> 11 <script class="testbody" type="text/javascript"> 12 // Test if audio can be replayed after ended. 13 var completed = false; 14 var playingCount = 0; 15 var endCount = 0; 16 17 function startTest() { 18 if (completed) 19 return; 20 21 var v = document.getElementById('v'); 22 v.play(); 23 } 24 25 function playbackStarted() { 26 if (completed) 27 return; 28 29 playingCount++; 30 } 31 32 function playbackEnded() { 33 if (completed) 34 return; 35 36 endCount++; 37 var v = document.getElementById('v'); 38 ok(v.currentTime >= 0.9 && v.currentTime <= 1.1, 39 "Checking currentTime at end: " + v.currentTime); 40 ok(v.ended, "Checking playback has ended"); 41 ok(playingCount > 0, "Expect at least one playing event"); 42 playingCount = 0; 43 if (endCount < 2) { 44 v.play(); 45 } else { 46 ok(endCount == 2, "Check playback after ended event"); 47 completed = true; 48 SimpleTest.finish(); 49 } 50 } 51 52 SimpleTest.waitForExplicitFinish(); 53 </script> 54 </pre> 55 <audio id='v' 56 onloadedmetadata='return startTest();' 57 onplaying='return playbackStarted();' 58 onended='return playbackEnded();'> 59 <source type='audio/x-wav' src='r11025_s16_c1.wav'> 60 </audio> 61 </body> 62 </html>