25 lines
551 B
Dart
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();
|
|
}
|