refactor(audio): 오디오 서비스 정리 및 SFX 풀 개선

This commit is contained in:
JiWoong Sul
2026-01-12 16:16:54 +09:00
parent 2bf7387a08
commit 32ecafd33d
2 changed files with 16 additions and 11 deletions

View File

@@ -174,7 +174,8 @@ class AudioService {
return; return;
} catch (e) { } catch (e) {
debugPrint( debugPrint(
'[AudioService] BGM player attempt ${attempt + 1} failed: $e'); '[AudioService] BGM player attempt ${attempt + 1} failed: $e',
);
_staticBgmPlayer = null; _staticBgmPlayer = null;
if (attempt == maxRetries - 1) { if (attempt == maxRetries - 1) {
debugPrint('[AudioService] BGM disabled'); debugPrint('[AudioService] BGM disabled');
@@ -269,7 +270,9 @@ class AudioService {
// "Loading interrupted"는 새 BGM 요청으로 인한 정상 중단 // "Loading interrupted"는 새 BGM 요청으로 인한 정상 중단
if (errorStr.contains('Loading interrupted') || if (errorStr.contains('Loading interrupted') ||
errorStr.contains('abort')) { errorStr.contains('abort')) {
debugPrint('[AudioService] BGM $name loading interrupted (new request)'); debugPrint(
'[AudioService] BGM $name loading interrupted (new request)',
);
return; // 플레이어 재생성 불필요 return; // 플레이어 재생성 불필요
} }

View File

@@ -12,11 +12,8 @@ import 'package:just_audio/just_audio.dart';
/// ///
/// 플레이어 인스턴스를 static으로 관리하여 핫 리로드에서도 안전합니다. /// 플레이어 인스턴스를 static으로 관리하여 핫 리로드에서도 안전합니다.
class SfxChannelPool { class SfxChannelPool {
SfxChannelPool({ SfxChannelPool({required this.name, this.poolSize = 4, double volume = 0.8})
required this.name, : _volume = volume;
this.poolSize = 4,
double volume = 0.8,
}) : _volume = volume;
/// 채널명 (디버그용) /// 채널명 (디버그용)
final String name; final String name;
@@ -76,7 +73,8 @@ class SfxChannelPool {
// 기존 플레이어가 있으면 재사용 (핫 리로드 대응) // 기존 플레이어가 있으면 재사용 (핫 리로드 대응)
if (_staticPlayers[name]!.isNotEmpty) { if (_staticPlayers[name]!.isNotEmpty) {
debugPrint( debugPrint(
'[SfxChannelPool:$name] Reusing ${_staticPlayers[name]!.length} existing players'); '[SfxChannelPool:$name] Reusing ${_staticPlayers[name]!.length} existing players',
);
_staticInitialized[name] = true; _staticInitialized[name] = true;
completer.complete(); completer.complete();
return; return;
@@ -96,9 +94,12 @@ class SfxChannelPool {
if (successCount > 0) { if (successCount > 0) {
_staticInitialized[name] = true; _staticInitialized[name] = true;
debugPrint( debugPrint(
'[SfxChannelPool:$name] Initialized with $successCount/$poolSize players'); '[SfxChannelPool:$name] Initialized with $successCount/$poolSize players',
);
} else { } else {
debugPrint('[SfxChannelPool:$name] All players failed - audio disabled'); debugPrint(
'[SfxChannelPool:$name] All players failed - audio disabled',
);
} }
completer.complete(); completer.complete();
@@ -140,7 +141,8 @@ class SfxChannelPool {
return player; return player;
} catch (e) { } catch (e) {
debugPrint( debugPrint(
'[SfxChannelPool:$name] Player $index attempt ${attempt + 1} failed: $e'); '[SfxChannelPool:$name] Player $index attempt ${attempt + 1} failed: $e',
);
if (attempt == maxRetries - 1) { if (attempt == maxRetries - 1) {
return null; return null;
} }