10 soundJs 初体验

最近想做一个h5的小游戏所以用上了soundjs。

还在开发中  http://www.hetenglife.com/mouse/game.html 刚刚把控制做完。

单个声音文件很简单

var soundID = "tiaoyue"

createjs.Sound.registerSound("./sound/sound.mp3",soundID);

function playSound() {
    createjs.Sound.play(soundID);
}

//当要用的时候直接调用playSound()即可

批量保存并调用声音的方法

/*声音调用*/
createjs.Sound.removeAllSounds();//防止声音,点击“首页”回到第0帧后,不能播放声音
var sounds = {path:"./sounds/",//assets是指声音文件
 
            manifest: [
			{id: "sy1", src: { mp3:"bgm.mp3"}},//sy1-20是你自定义的ID,是你要调用的
 
    ]};
createjs.Sound.registerPlugins([createjs.WebAudioPlugin, createjs.FlashAudioPlugin]);
createjs.Sound.alternateExtensions = ["mp3"];
createjs.Sound.registerSounds(sounds);
 
createjs.Sound.stop(); // 停止播放背景声音
 
 
 
//第2帧后面
//
var props = new createjs.PlayPropsConfig().set({
	interrupt: createjs.Sound.INTERRUPT_ANY,
	loop: -1,
	volume: 0.5
});
createjs.Sound.play('sy1', props); // Sound:play

其他属性

interrupt - 如果已经播放了最大个数的声音实例,如何中断正在播放的具有相同资源的任意的音频实例。可选值定义在 'Sound' 类的 'INTERRUPT_TYPE' 常量,默认由 'defaultInterruptBehavior' 定义。
delay - 音频开始播放的延迟时间,单位 'ms'
offset - 音频开始播放的偏移时间量,单位 'ms'
loop - 音频循环播放次数。默认是 '0-不循环', -1 - 无限循环
volume - 声音的音量,0-1之间。注意:主音量应用于单个音量
pan - 声音的左-右声部(如果支持),在-1(左)和1(右)之间。
startTime - 创建 '音频精灵'(和 duration 一起使用) 开始播放和循环时的初始偏移量,单位 'ms'
duration - 创建 '音频精灵'(和 startTime 一起使用) 播放剪辑的时间量,单位 'ms'

猜你喜欢

转载自www.cnblogs.com/heteng/p/12499269.html
今日推荐