2 <title>Test of concurrent HTML5 audio
</title>
5 <p>Test that multiple audio elements can play concurrently.
</p>
7 <script src=video-test.js
></script>
8 <script src=media-file.js
></script>
10 var maxPlayers
= 2; // Number of concurrent audio elements to test. For larger values a longer media file is needed.
11 var audioElementCount
= 0;
13 function errorListener(event
)
15 logResult(false, "Element " + audioElementCount
+ " caught 'error' event, audio.error.code = " + this.error
.code
);
19 function canplaythroughListener(event
)
21 consoleWrite("EVENT(" + audioElementCount
+ ", canplaythrough)");
23 testExpected(audioElementCount
+ ", testElement.currentTime", 0);
27 function playingListener(event
)
29 consoleWrite("EVENT(" + audioElementCount
+ ", playing)");
32 function timeupdateListener(event
)
35 testExpected(audioElementCount
+ ", testElement.currentTime", 0, '>');
36 this.removeEventListener('timeupdate', timeupdateListener
);
37 if (++audioElementCount
>= maxPlayers
) {
38 // All audio elements have been started playing. Make sure
39 // all of them are still playing.
40 consoleWrite("Making sure all " + maxPlayers
+ " audio elements are in playing state:");
41 for (var i
= 0; i
< maxPlayers
; i
++) {
42 testElement
= document
.getElementsByTagName('audio')[i
];
43 testExpected(i
+ ", testElement.paused", false);
47 // Start the next audio element
48 testAudioElement(audioElementCount
);
52 function testAudioElement(count
)
54 var audioElement
= document
.getElementsByTagName('audio')[count
];
55 audioElement
.addEventListener('error', errorListener
);
56 audioElement
.addEventListener('canplaythrough', canplaythroughListener
);
57 audioElement
.addEventListener('timeupdate', timeupdateListener
);
58 audioElement
.addEventListener('playing', playingListener
);
59 audioElement
.src
= findMediaFile("audio", "content/silence");
62 consoleWrite("Starting a total of " + maxPlayers
+ " concurrent audio elements.");
63 for (var i
= 0; i
< maxPlayers
; i
++)
64 document
.write("<audio controls></audio>");