minijsound is a minimal javascript sound engine class with preload and without the need of audio tags.

In less than 1Kb you have a simple class to declare your sounds URLs, to preload all sounds (useful for html5 games or multimedia web apps) and to play them immediately having back a reference of the Audio object (to pause it, replay it, etc..).

No audio TAG is required in your DOM.

Enjoy it!
d

Source code available on JSFiddle
http://jsfiddle.net/onyrix/8ackmqea/

minijsound – minimal javascript sound engine – source code

// minijsound
// a minimal javascript sound library with preload
// written by Dino Olivieri
// https://www.onyrix.com
//
var minijsound = {
soundLibrary:{
sound1:”https://upload.wikimedia.org/wikipedia/commons/0/01/01_Pista_1.ogg”,
sound2:”https://upload.wikimedia.org/wikipedia/commons/4/43/Ubuntu_sound.ogg”
},
soundCache:{},
preLoadSounds:function(){
for(var k in this.soundLibrary){
this.soundCache[k] = new Audio();
this.soundCache[k].src = this.soundLibrary[k];
this.soundCache[k].load();
console.log(‘preloaded sound: ‘+this.soundCache[k].src);
}
},
playSound:function(k){
try{
return this.soundCache[k].play();
}catch(err){
console.log(‘playSound:error ‘+err.message);
}
}
}
// example
minijsound.preLoadSounds();
var s1 = minijsound.playSound(“sound1”);
var s2 = minijsound.playSound(“sound2”);

Dino Olivieri’s Music

Dino Olivieri on Soundcloud
Dino Olivieri on Bandcamp
Dino Olivieri on Spotify
Dino Olivieri on Apple Music
Dino Olivieri on Amazon Music
Dino Olivieri on Napster
Dino Olivieri on Deezer
Dino Olivieri on Tidal
Dino Olivieri on Youtube Music
Dino Olivieri on AWA Music
Dino Olivieri on KKBOX
Dino Olivieri on Yandex