1
0
Fork 0

Added missing files... oops!

This commit is contained in:
Starbeamrainbowlabs 2015-02-19 20:21:07 +00:00
parent 6777e14664
commit d4c0f2683d
5 changed files with 56 additions and 0 deletions

55
example.html Normal file
View File

@ -0,0 +1,55 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>SoundBox.js Example</title>
</head>
<body>
<h1>SoundBox.js Example</h1>
<p>All sounds from <a href="http://www.bfxr.net/" target="_blank">Bfxr</a>.</p>
<button onclick="play_sound_1();">Play Sound 1</button>
<button onclick="play_sound_2();">Play Sound 2</button>
<button onclick="play_sound_3();">Play Sound 3</button>
<button onclick="play_multiple_sounds();">Play Multiple Sounds</button>
<!----------->
<style>
body { font-family: sans-serif; }
</style>
<script src="soundbox.min.js"></script>
<script>
window.addEventListener("load", function(event) {
window.soundbox = new SoundBox();
soundbox.load("beep1", "examplesounds/beep1.wav");
soundbox.load("beep2", "examplesounds/beep2.wav");
soundbox.load("beep3", "examplesounds/beep3.wav");
});
function play_sound_1()
{
soundbox.play("beep1");
}
function play_sound_2()
{
soundbox.play("beep2");
}
function play_sound_3()
{
soundbox.play("beep3");
}
function play_multiple_sounds()
{
soundbox.play("beep1", function() {
soundbox.play("beep2", function() {
soundbox.play("beep3");
});
});
}
</script>
</body>
</html>

BIN
examplesounds/beep1.wav Normal file

Binary file not shown.

BIN
examplesounds/beep2.wav Normal file

Binary file not shown.

BIN
examplesounds/beep3.wav Normal file

Binary file not shown.

1
soundbox.min.js vendored Normal file
View File

@ -0,0 +1 @@
function SoundBox(){this.sounds={},this.sound_callbacks={},this.load=function(s,n){this.sounds[s]=new Audio(n),this.sounds[s].addEventListener("ended",function(n){n.target.currentTime=0,"function"==typeof this.sound_callbacks[s]&&(this.sound_callbacks[s](s),delete this.sound_callbacks[s])}.bind(this))},this.remove=function(s){"undefined"!=typeof this.sounds&&delete this.sounds[s],"function"==typeof this.sound_callbacks&&delete this.sound_callbacks[s]},this.play=function(s,n){return"undefined"==typeof this.sounds[s]?(console.error("Can't find sound called '"+s+"'."),!1):("function"==typeof n&&(this.sound_callbacks[s]=n),void this.sounds[s].play())}}