From f0b306a2ab89f3e60a4fc7594425d59614484cc9 Mon Sep 17 00:00:00 2001 From: David Kotnik Date: Sun, 11 Jan 2026 00:08:23 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20AUDIO=20FIX=20-=20No=20More=20Cr?= =?UTF-8?q?ashes!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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! --- src/scenes/StoryScene.js | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/scenes/StoryScene.js b/src/scenes/StoryScene.js index 5247ebca9..16a6bf76e 100644 --- a/src/scenes/StoryScene.js +++ b/src/scenes/StoryScene.js @@ -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'); } }