1.实现效果。
让一个背景声音文件,不停的循环
2.代码
//第0帧
/*声音调用*/
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
3.其他属性
interrupt - 如果已经播放了最大个数的声音实例,如何中断正在播放的具有相同资源的任意的音频实例。可选值定义在 'Sound' 类的 'INTERRUPT_TYPE' 常量,默认由 'defaultInterruptBehavior' 定义。
delay - 音频开始播放的延迟时间,单位 'ms'
offset - 音频开始播放的偏移时间量,单位 'ms'
loop - 音频循环播放次数。默认是 '0-不循环', -1 - 无限循环
volume - 声音的音量,0-1之间。注意:主音量应用于单个音量
pan - 声音的左-右声部(如果支持),在-1(左)和1(右)之间。
startTime - 创建 '音频精灵'(和 duration 一起使用) 开始播放和循环时的初始偏移量,单位 'ms'
duration - 创建 '音频精灵'(和 startTime 一起使用) 播放剪辑的时间量,单位 'ms'