|
@ -1,17 +1,39 @@ |
|
|
// 音频处理类
|
|
|
// 音频处理类
|
|
|
function Sound() { |
|
|
// function Sound() {
|
|
|
this.lib = library; |
|
|
// this.lib = library;
|
|
|
|
|
|
|
|
|
this.music = {}; |
|
|
// this.music = {};
|
|
|
} |
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// Sound.of = function () {
|
|
|
|
|
|
// const instance = new Sound();
|
|
|
|
|
|
// instance.init();
|
|
|
|
|
|
// return instance;
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
// Sound.prototype.init = function () {
|
|
|
|
|
|
// createjs.Sound.alternateExtensions = ['mp3'];
|
|
|
|
|
|
// console.log('createjs.Sound: ', createjs.Sound);
|
|
|
|
|
|
// const sounds = [
|
|
|
|
|
|
// { src: 'public/sounds/bgmMusic.mp3', id: 'bgm' },
|
|
|
|
|
|
// { src: 'public/sounds/excitationMusic.mp3', id: 'excitation' },
|
|
|
|
|
|
// { src: 'public/sounds/amazing.mp3', id: 'amazing' },
|
|
|
|
|
|
// { src: 'public/sounds/unbelievable.mp3', id: 'unbelievable' },
|
|
|
|
|
|
// ];
|
|
|
|
|
|
// createjs.Sound.addEventListener('fileload', function (event) {
|
|
|
|
|
|
// console.log('event: ', event);
|
|
|
|
|
|
// this.music[event.id] = createjs.Sound.createInstance(event.id);
|
|
|
|
|
|
// });
|
|
|
|
|
|
// createjs.Sound.registerSounds(sounds, '../../');
|
|
|
|
|
|
// this.playBgm();
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
Sound.of = function () { |
|
|
// Sound.prototype.playBgm = function () {
|
|
|
const instance = new Sound(); |
|
|
// this.music.bgm && this.music.bgm.play({ loop: -1, volume: 0.3 }); // 播放背景音乐
|
|
|
instance.init(); |
|
|
// };
|
|
|
return instance; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
Sound.prototype.init = function () { |
|
|
let music = {}; |
|
|
|
|
|
function initSound() { |
|
|
createjs.Sound.alternateExtensions = ['mp3']; |
|
|
createjs.Sound.alternateExtensions = ['mp3']; |
|
|
const sounds = [ |
|
|
const sounds = [ |
|
|
{ src: 'public/sounds/bgmMusic.mp3', id: 'bgm' }, |
|
|
{ src: 'public/sounds/bgmMusic.mp3', id: 'bgm' }, |
|
@ -20,11 +42,7 @@ Sound.prototype.init = function () { |
|
|
{ src: 'public/sounds/unbelievable.mp3', id: 'unbelievable' }, |
|
|
{ src: 'public/sounds/unbelievable.mp3', id: 'unbelievable' }, |
|
|
]; |
|
|
]; |
|
|
createjs.Sound.addEventListener('fileload', function (event) { |
|
|
createjs.Sound.addEventListener('fileload', function (event) { |
|
|
this.music[event.id] = createjs.Sound.createInstance(event.id); |
|
|
music[event.id] = createjs.Sound.createInstance(event.id); |
|
|
}); |
|
|
}); |
|
|
createjs.Sound.registerSounds(sounds, '../../'); |
|
|
createjs.Sound.registerSounds(sounds, '../../'); |
|
|
}; |
|
|
} |
|
|
|
|
|
|
|
|
Sound.prototype.playBgm = function () { |
|
|
|
|
|
this.music.bgm && this.music.bgm.play({ loop: -1, volume: 0.3 }); // 播放背景音乐
|
|
|
|
|
|
}; |
|
|
|
|
|