so I’m trying to get this music code to work. it’s an evolution of the above code. what I’m trying to do is load all the keys for which ever specific music to play in which ever specific level. Problem is, I get :
Sound track{s} :: bgMusic
TitleScene.js:288 Sound data {s} :: {volume: 0.1, loop: true}
phaser.js:82849 Audio cache entry missing: undefined
phaser.js:26468 Uncaught TypeError: Cannot set property 'seek' of undefined
But I have the correct files in the correct folder which is 'assets'
, obviously & the files are not corrupt as they both play fine in my music player. here is what I’m defining in 'preload ( )'
:
preload : function ( ) {
console.log ( 'HELLO FROM TITLE SCENE!' );
this.__soundTrack = [
'bgMusic', 'lvl1Music', 'lvl2Music',
];
this.__soundData = [
{
volume : 0.1,
loop : true,
},
{
volume : 0.5,
loop : true,
},
];
this.__stats = new Stats ( );
document.body.appendChild ( this.__stats.dom );
},
here is what i’m doing in 'create ( )'
:
this.model = this.sys.game.globals.model;
this.__soundTrackCount = ( this.__soundTrack.length );
for ( this.__i = 0; this.__i < ( this.__soundTrackCount - 1 ); this.__i++ ) {
console.log ( 'Sound track{s} :: ', this.__soundTrack [ this.__i ] );
console.log ( 'Sound data {s} :: ', this.__soundData [ this.__i ] );
this.createAudio ({
soundID : this.__soundTrack [ this.__i ],
soundData : this.__soundData [ this.__i ]
});
}
here is how I’m loading the files in 'PreloaderScene.js'
:
preload ( ) {
this.load.audio ( 'bgMusic', [
'assets/TownTheme.mp3',
] );
this.load.audio ( 'lvl1Music', [
'assets/TownTheme2.mp3',
] );
}
here is the 'createAudio ( )'
function :
createAudio : function ( __objData ) {
this.__objData = __objData;
this.__soundID = [ this.__objData.soundID ];
this.__soundData = [ this.__objData.soundData ];
if ( this.model.musicOn === true && this.model.bgMusicPlaying === false ) {
this.__sound = [ ];
for ( this.__i = 0; this.__i < ( this.__soundTrack.length ); this.__i++ ) {
this.__sound [ this.__i ] = this.sound.add (
this.__soundID [ this.__i ], this.__soundData [ this.__i ]
);
this.__sound [ this.__i ].play ( );
}
this.model.bgMusicPlaying = true;
this.sys.game.globals.music [ this.__i ] = this.__sound [ this.__i ];
}
else
{
this.sys.game.globals.music [ this.__i ].stop ( );
this.model.bgMusicPlaying = false;
}
if ( this.model.bgMusicPlaying === false ) {
this.sys.game.globals.music [ this.__i ].play ();
this.sound.pauseOnBlur = false;
this.model.bgMusicPlaying = true;
}
},
Any help is GREATLY appreciated!