1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
<html>
<title>Test of concurrent HTML5 audio</title>
<body>
<p>Test that multiple audio elements can play concurrently.</p>
<!-- TODO(philipj): Convert test to testharness.js. crbug.com/588956
(Please avoid writing new tests using video-test.js) -->
<script src=video-test.js></script>
<script src=media-file.js></script>
<script>
var maxPlayers = 2; // Number of concurrent audio elements to test. For larger values a longer media file is needed.
var audioElementCount = 0;
function errorListener(event)
{
logResult(false, "Element " + audioElementCount + " caught 'error' event, audio.error.code = " + this.error.code);
endTest();
}
function canplaythroughListener(event)
{
consoleWrite("EVENT(" + audioElementCount + ", canplaythrough)");
testElement = this;
testExpected(audioElementCount + ", testElement.currentTime", 0);
this.play();
}
function playingListener(event)
{
consoleWrite("EVENT(" + audioElementCount + ", playing)");
}
function timeupdateListener(event)
{
testElement = this;
testExpected(audioElementCount + ", testElement.currentTime", 0, '>');
this.removeEventListener('timeupdate', timeupdateListener);
if (++audioElementCount >= maxPlayers) {
// All audio elements have been started playing. Make sure
// all of them are still playing.
consoleWrite("Making sure all " + maxPlayers + " audio elements are in playing state:");
for (var i = 0; i < maxPlayers; i++) {
testElement = document.getElementsByTagName('audio')[i];
testExpected(i + ", testElement.paused", false);
}
endTest();
} else {
// Start the next audio element
testAudioElement(audioElementCount);
}
}
function testAudioElement(count)
{
var audioElement = document.getElementsByTagName('audio')[count];
audioElement.addEventListener('error', errorListener);
audioElement.addEventListener('canplaythrough', canplaythroughListener);
audioElement.addEventListener('timeupdate', timeupdateListener);
audioElement.addEventListener('playing', playingListener);
audioElement.src = findMediaFile("audio", "content/silence");
}
consoleWrite("Starting a total of " + maxPlayers + " concurrent audio elements.");
for (var i = 0; i < maxPlayers; i++)
document.write("<audio controls></audio>");
testAudioElement(0);
</script>
</body>
</html>
|