-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.html
64 lines (52 loc) · 1.96 KB
/
index.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<html lang="en">
<head>
<title>Play Sounds with JavaScript</title>
<meta charset="utf-8">
<script src="sounds.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<h1>Some JS to play sounds! 🎹</h1>
<p>This code uses the Web Audio API to play sounds in the browser.</p>
<h2>Try it out</h2>
<ul>
<li><a href="#" onclick="playSound('dead'); return false;">Dead</a></li>
<li><a href="#" onclick="playSound('smash'); return false;">Smash</a></li>
<li><a href="#" onclick="playSound('ping'); return false;">Ping</a></li>
<li><a href="#" onclick="playSound('bump');">Bump</a></li>
<li><a href="#" onclick="playSound('jump');">Jump</a></li>
<li><a href="#" onclick="playSound('coin');">Coin</a></li>
</ul>
<h2>Usage</h2>
<p>
To get started, include the sounds.js file in <strong>head</strong> of your project.
</p>
<pre class="code"><script src="sounds.js" type="text/javascript"></script></pre>
<p>Then edit the <strong>sounds</strong> object to add your sounds...
<pre class="code">
"dead" : {
url : "sounds/dead.wav"
},
"ping" : {
url : "sounds/ping.mp3",
volume : .5
}
</pre>
<p>
The name of the sound above will be <strong>"dead"</strong>.
You can add an optional <strong>volume</strong> property, which can range from 0 to 1.
</p>
<h2>Playing a Sound</h2>
<p>To play a sound, call the method with the name of the sound.</p>
<div class="code-wrapper">
<pre class="code">playSound("dead");</pre>
<a href='#' onclick="playSound('dead'); return false;">🎹</a>
</div>
<p>You can also change the volume dynamically, like this...</p>
<div class="code-wrapper">
<pre class="code">playSound("dead", { volume: .4 });</pre>
<a href='#' onclick="playSound('dead', { volume: .4 }); return false;">🎹</a>
</div>
</body>
</html>