HTML5 的音乐工具库:Sound.js
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
本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!