From 736d3f22384765ec2f3d6015ca9c019cf86951e0 Mon Sep 17 00:00:00 2001 From: Calcitem Date: Sun, 16 May 2021 12:30:06 +0800 Subject: [PATCH] flutter: audio: Do not _playSound soundId is null (WAR) When soundId is null, config play sound is enabled. I don't known the root cause. --- src/ui/flutter_app/lib/services/audios.dart | 95 +++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/src/ui/flutter_app/lib/services/audios.dart b/src/ui/flutter_app/lib/services/audios.dart index 9ee4ff8e..35ef2490 100644 --- a/src/ui/flutter_app/lib/services/audios.dart +++ b/src/ui/flutter_app/lib/services/audios.dart @@ -45,26 +45,113 @@ class Audios { _soundpool ??= Soundpool(); + if (_soundpool == null) { + if (Config.developerMode) { + assert(false); + } + print("[audio] Error: _soundpool is null."); + return; + } + drawSoundId ??= await _soundpool!.load(await rootBundle.load("assets/audios/draw.mp3")); + if (drawSoundId == null) { + if (Config.developerMode) { + assert(false); + } + print("[audio] Error: drawSoundId is null."); + return; + } + flySoundId ??= await _soundpool!.load(await rootBundle.load("assets/audios/fly.mp3")); + if (flySoundId == null) { + if (Config.developerMode) { + assert(false); + } + print("[audio] Error: flySoundId is null."); + return; + } + goSoundId ??= await _soundpool!.load(await rootBundle.load("assets/audios/go.mp3")); + if (goSoundId == null) { + if (Config.developerMode) { + assert(false); + } + print("[audio] Error: goSoundId is null."); + return; + } + illegalSoundId = await _soundpool! .load(await rootBundle.load("assets/audios/illegal.mp3")); + if (illegalSoundId == null) { + if (Config.developerMode) { + assert(false); + } + print("[audio] Error: illegalSoundId is null."); + return; + } + loseSoundId ??= await _soundpool!.load(await rootBundle.load("assets/audios/lose.mp3")); + if (loseSoundId == null) { + if (Config.developerMode) { + assert(false); + } + print("[audio] Error: loseSoundId is null."); + return; + } + millSoundId ??= await _soundpool!.load(await rootBundle.load("assets/audios/mill.mp3")); + if (millSoundId == null) { + if (Config.developerMode) { + assert(false); + } + print("[audio] Error: millSoundId is null."); + return; + } + placeSoundId ??= await _soundpool! .load(await rootBundle.load("assets/audios/place.mp3")); + if (placeSoundId == null) { + if (Config.developerMode) { + assert(false); + } + print("[audio] Error: placeSoundId is null."); + return; + } + removeSoundId ??= await _soundpool! .load(await rootBundle.load("assets/audios/remove.mp3")); + if (removeSoundId == null) { + if (Config.developerMode) { + assert(false); + } + print("[audio] Error: removeSoundId is null."); + return; + } + selectSoundId ??= await _soundpool! .load(await rootBundle.load("assets/audios/select.mp3")); + if (selectSoundId == null) { + if (Config.developerMode) { + assert(false); + } + print("[audio] Error: selectSoundId is null."); + return; + } + winSoundId ??= await _soundpool!.load(await rootBundle.load("assets/audios/win.mp3")); + if (winSoundId == null) { + if (Config.developerMode) { + assert(false); + } + print("[audio] Error: winSoundId is null."); + return; + } } static Future _playSound(var soundId) async { @@ -72,6 +159,14 @@ class Audios { return; } + if (soundId == null) { + if (Config.developerMode) { + assert(false); + } + print("[audio] Error: soundId is null."); + return; + } + _alarmSoundStreamId = await _soundpool!.play(await soundId); }