🔧 AUDIO FIX - No More Crashes!

PROBLEM:
- EncodingError: Unable to decode audio
- Game crashes if audio fails

SOLUTION:
- Wrapped playNoirMusic() in try/catch
- Alternative loading if audio not preloaded
- Game continues even if music fails

CHANGES:
 Try/catch around all audio operations
 Fallback loader if forest_ambient not ready
 Error messages non-critical
 Game never crashes from audio

CONSOLE OUTPUT:
Success: '🎵 Noir atmosphere music playing'
Warning: '⚠️ forest_ambient not loaded yet - trying alternative'
Error: ' Audio error (non-critical)' + continues

 AUDIO ERRORS WON'T CRASH GAME!
This commit is contained in:
2026-01-11 00:08:23 +01:00
parent 61d5eb7242
commit f0b306a2ab

View File

@@ -144,15 +144,32 @@ class StoryScene extends Phaser.Scene {
playNoirMusic() {
// Play forest evening ambience (noir atmosphere)
if (this.sound.get('forest_ambient')) {
const music = this.sound.add('forest_ambient', {
volume: 0.3,
loop: true
});
music.play();
console.log('🎵 Noir atmosphere music playing at 30% volume');
} else {
console.warn('⚠️ forest_ambient music not loaded - add to preload()');
try {
if (this.sound.get('forest_ambient')) {
const music = this.sound.add('forest_ambient', {
volume: 0.3,
loop: true
});
music.play();
console.log('🎵 Noir atmosphere music playing at 30% volume');
} else {
console.warn('⚠️ forest_ambient not loaded yet - trying alternative');
// Try to load and play immediately
this.load.audio('forest_ambient', 'assets/audio/music/forest_ambient.mp3');
this.load.once('complete', () => {
try {
const music = this.sound.add('forest_ambient', { volume: 0.3, loop: true });
music.play();
console.log('🎵 Loaded and playing forest_ambient');
} catch (e) {
console.error('❌ Failed to play music:', e.message);
}
});
this.load.start();
}
} catch (error) {
console.error('❌ Audio error (non-critical):', error.message);
console.log('✅ Game continues without music');
}
}