|
@@ -5,18 +5,18 @@ class AudioManager {
|
|
|
static final AudioManager _instance = AudioManager._internal();
|
|
|
final AudioPlayer _audioPlayer = AudioPlayer();
|
|
|
bool _isPlaying = false;
|
|
|
-
|
|
|
+
|
|
|
factory AudioManager() {
|
|
|
return _instance;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
AudioManager._internal();
|
|
|
-
|
|
|
+
|
|
|
Future<void> playSound(String sound, double volume, bool loop) async {
|
|
|
if (_isPlaying) {
|
|
|
await stopSound();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// For this example, we're using dummy sound mapping
|
|
|
// In a real app, you would have actual sound files
|
|
|
String soundAsset;
|
|
@@ -33,33 +33,34 @@ class AudioManager {
|
|
|
default:
|
|
|
soundAsset = 'assets/sounds/dripping.mp3';
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
await _audioPlayer.setVolume(volume);
|
|
|
- await _audioPlayer.setReleaseMode(loop ? ReleaseMode.loop : ReleaseMode.release);
|
|
|
+ await _audioPlayer
|
|
|
+ .setReleaseMode(loop ? ReleaseMode.loop : ReleaseMode.release);
|
|
|
await _audioPlayer.play(AssetSource(soundAsset));
|
|
|
_isPlaying = true;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
Future<void> stopSound() async {
|
|
|
await _audioPlayer.stop();
|
|
|
_isPlaying = false;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
Future<void> triggerVibration() async {
|
|
|
if (await Vibration.hasVibrator() ?? false) {
|
|
|
Vibration.vibrate(pattern: [500, 1000, 500, 1000], repeat: 1);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
Future<void> stopVibration() async {
|
|
|
if (await Vibration.hasVibrator() ?? false) {
|
|
|
Vibration.cancel();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
Future<void> dispose() async {
|
|
|
await stopSound();
|
|
|
await stopVibration();
|
|
|
await _audioPlayer.dispose();
|
|
|
}
|
|
|
-}
|
|
|
+}
|