lottis_birthday_escaperoom_app/lib/util.dart
2024-08-17 05:19:32 +02:00

25 lines
551 B
Dart

import 'package:audioplayers/audioplayers.dart';
class AudioPlayerSingleton {
static AudioPlayerSingleton? _instance;
late AudioPlayer _audioPlayer;
AudioPlayerSingleton._() {
_audioPlayer = AudioPlayer();
}
static AudioPlayerSingleton get instance {
_instance ??= AudioPlayerSingleton._();
return _instance!;
}
Future<void> playBeepSound() async {
await _audioPlayer.play(AssetSource('sounds/beep.mp3'));
}
}
// Usage:
Future<void> playBeepSound() async {
await AudioPlayerSingleton.instance.playBeepSound();
}