lottis_birthday_escaperoom_app/lib/util.dart

25 lines
551 B
Dart
Raw Normal View History

2024-08-17 03:19:32 +00:00
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();
}