🔧 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:
@@ -144,6 +144,7 @@ class StoryScene extends Phaser.Scene {
|
|||||||
|
|
||||||
playNoirMusic() {
|
playNoirMusic() {
|
||||||
// Play forest evening ambience (noir atmosphere)
|
// Play forest evening ambience (noir atmosphere)
|
||||||
|
try {
|
||||||
if (this.sound.get('forest_ambient')) {
|
if (this.sound.get('forest_ambient')) {
|
||||||
const music = this.sound.add('forest_ambient', {
|
const music = this.sound.add('forest_ambient', {
|
||||||
volume: 0.3,
|
volume: 0.3,
|
||||||
@@ -152,7 +153,23 @@ class StoryScene extends Phaser.Scene {
|
|||||||
music.play();
|
music.play();
|
||||||
console.log('🎵 Noir atmosphere music playing at 30% volume');
|
console.log('🎵 Noir atmosphere music playing at 30% volume');
|
||||||
} else {
|
} else {
|
||||||
console.warn('⚠️ forest_ambient music not loaded - add to preload()');
|
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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user