|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <head> |
|
4 <title>Test audio-channel-changed & visible-audio-channel-changed mozChromeEvent</title> |
|
5 </head> |
|
6 <body> |
|
7 <div id="content"></div> |
|
8 <script> |
|
9 var normalAudio; |
|
10 var contentAudio; |
|
11 var notificationAudio; |
|
12 var alarmAudio; |
|
13 var telephonyAudio; |
|
14 var ringerAudio; |
|
15 var publicnotificationAudio; |
|
16 |
|
17 function playWithAudioType(audio, type) { |
|
18 audio.mozAudioChannelType = type; |
|
19 audio.src = "test.ogg"; |
|
20 audio.loop = true; |
|
21 |
|
22 audio.play(); |
|
23 } |
|
24 |
|
25 function runTest() { |
|
26 // normal channel. |
|
27 normalAudio = new Audio(); |
|
28 playWithAudioType(normalAudio, 'normal'); |
|
29 |
|
30 // content channel. |
|
31 contentAudio = new Audio(); |
|
32 playWithAudioType(contentAudio, 'content'); |
|
33 |
|
34 // notification channel. |
|
35 notificationAudio = new Audio(); |
|
36 playWithAudioType(notificationAudio, 'notification'); |
|
37 |
|
38 // alarm channel. |
|
39 alarmAudio = new Audio(); |
|
40 playWithAudioType(alarmAudio, 'alarm'); |
|
41 |
|
42 // telephony channel. |
|
43 telephonyAudio = new Audio(); |
|
44 playWithAudioType(telephonyAudio, 'telephony'); |
|
45 |
|
46 // ringer channel. |
|
47 ringerAudio = new Audio(); |
|
48 playWithAudioType(ringerAudio, 'ringer'); |
|
49 |
|
50 // publicnotification channel. |
|
51 publicnotificationAudio = new Audio(); |
|
52 playWithAudioType(publicnotificationAudio, 'publicnotification'); |
|
53 |
|
54 window.addEventListener('hashchange', function(event) { |
|
55 if (location.hash == "#pauseAudio") { |
|
56 publicnotificationAudio.pause(); |
|
57 ringerAudio.pause(); |
|
58 telephonyAudio.pause(); |
|
59 } |
|
60 |
|
61 if (location.hash == "#pauseAudioFollowing") { |
|
62 alarmAudio.pause(); |
|
63 notificationAudio.pause(); |
|
64 contentAudio.pause(); |
|
65 normalAudio.pause(); |
|
66 } |
|
67 }, false); |
|
68 } |
|
69 |
|
70 function checkBackgroundStatus() { |
|
71 if (location.hash == "#fg") { |
|
72 runTest(); |
|
73 return; |
|
74 } |
|
75 |
|
76 if (document.hidden) { |
|
77 runTest(); |
|
78 return; |
|
79 } |
|
80 |
|
81 document.addEventListener('visibilitychange', function visibilityChange() { |
|
82 if (document.hidden) { |
|
83 runTest(); |
|
84 } |
|
85 }); |
|
86 } |
|
87 |
|
88 SpecialPowers.pushPermissions( |
|
89 [{ "type": "audio-channel-content", "allow": 1, "context": document }, |
|
90 { "type": "audio-channel-notification", "allow": 1, "context": document }, |
|
91 { "type": "audio-channel-alarm", "allow": 1, "context": document }, |
|
92 { "type": "audio-channel-telephony", "allow": 1, "context": document }, |
|
93 { "type": "audio-channel-ringer", "allow": 1, "context": document }, |
|
94 { "type": "audio-channel-publicnotification", "allow": 1, "context": document }], |
|
95 checkBackgroundStatus); |
|
96 |
|
97 </script> |
|
98 </body> |
|
99 </html> |