check initialisation of audio fixes #326

Although not a problem in production there was an error when hot reloading  or using hot restart.

we now ckeck the initialisation of the autio service
This commit is contained in:
Leptopoda 2021-10-19 12:24:20 +02:00
parent 4d53769dca
commit bffda2b816
No known key found for this signature in database
GPG Key ID: 661B059EDE309F11
1 changed files with 11 additions and 4 deletions

View File

@ -56,9 +56,16 @@ class Audios {
static late final int _winSoundId;
static bool isTemporaryMute = false;
static const _tag = '[audio]';
static Future<void> loadSounds() async {
if (Platform.isWindows) {
debugPrint("[audio] Audio Player does not support Windows.");
debugPrint("$_tag Audio Player does not support Windows.");
return;
}
if (_initialized) {
debugPrint("$_tag Audio Player is already initialized.");
return;
}
@ -108,7 +115,7 @@ class Audios {
static Future<void> _playSound(Sound sound) async {
assert(!Platform.isWindows);
late final int soundId;
final int soundId;
switch (sound) {
case Sound.draw:
@ -169,9 +176,9 @@ class Audios {
return;
}
// If the platform is windwos [_initialized] should be false thus this code shouldn't be executed
if (Platform.isWindows) {
debugPrint("audio players is not support Windows.");
return;
assert(false);
}
// TODO: isn't debug chain meant to catch errors? so why catching them in here and not in onError??