-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathaudio.html
47 lines (43 loc) · 1.34 KB
/
audio.html
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
<html>
<head>
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0, maximum-scale=1, user-scalable=no, minimal-ui">
<style>
html, body, #c {
width: 100%;
height: 100%;
font-size: xx-large;
}
#c {
text-align: center;
}
</style>
</head>
<body>
<div id="c">Click to play a sound</d>
</body>
<script src="js/audio.js"></script>
<script>
var audioMgr = new AudioManager({
fire: { filename: "assets/snds/fire.ogg", samples: 8, },
explosion: { filename: "assets/snds/explosion.ogg", samples: 6, },
hitshield: { filename: "assets/snds/hitshield.ogg", samples: 6, },
launch: { filename: "assets/snds/launch.ogg", samples: 2, },
gameover: { filename: "assets/snds/gameover.ogg", samples: 1, },
play: { filename: "assets/snds/play.ogg", samples: 1, },
});
var snd = 0;
function playSound() {
console.log("play snd:" + snd);
switch (snd) {
case 0: audioMgr.playSound('fire'); break;
case 1: audioMgr.playSound('explosion'); break;
case 2: audioMgr.playSound('hitshield'); break;
case 3: audioMgr.playSound('launch'); break;
case 4: audioMgr.playSound('gameover'); break;
case 5: audioMgr.playSound('play'); break;
}
snd = (snd + 1) % 6;
}
document.getElementById("c").addEventListener('click', playSound, false);
</script>
</html>