HTML5 的音乐工具库:Sound.js
jopen
9年前
Audio & WebAudio的一个封装用于播放一个正常音频文件。
</div> Use HTML5 Audio: var sound = new Sound({ id: "bgm-1", src: "res/bgm-1.mp3", loop: false, volume: 1, tag: "bg", channel: 4, useWebAudio: false, }); sound.load(); sound.onLoad = function(){ this.play(); }
Use WebAudio :
var sound = new Sound({ id: "sfx-1", src: "res/sfx-1.mp3", loop: false, volume: 1, tag: "sfx", channel: 2, useWebAudio: true, }); sound.load(); sound.onLoad = function(){ this.play(); }
useWebAudio: default is true. It will try to use WebAudio first.
channel: for Multi Channel .
sound.play(); setTimeout(function(){ // if channel <=1 , // the prev playing will be stopped. // else , another there will be a new playing sound.play(); },1000);
tag: you can do something to many sounds by tag. example:
Sound.setMuteByTag("bg", true)
all sounds that tag=="bg" will be muted.
=====================
Sound.loadSounds : load sounds in batch
... ...
More features in Source Code :P