import 'package:audioplayers/audioplayers.dart'; import 'package:vibration/vibration.dart'; class AudioManager { static final AudioManager _instance = AudioManager._internal(); final AudioPlayer _audioPlayer = AudioPlayer(); bool _isPlaying = false; factory AudioManager() { return _instance; } AudioManager._internal(); Future 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; switch (sound) { case 'Dripping': soundAsset = 'assets/sounds/dripping.mp3'; break; case 'Alarm': soundAsset = 'assets/sounds/alarm.mp3'; break; case 'Bell': soundAsset = 'assets/sounds/bell.mp3'; break; default: soundAsset = 'assets/sounds/dripping.mp3'; } await _audioPlayer.setVolume(volume); await _audioPlayer .setReleaseMode(loop ? ReleaseMode.loop : ReleaseMode.release); await _audioPlayer.play(AssetSource(soundAsset)); _isPlaying = true; } Future stopSound() async { await _audioPlayer.stop(); _isPlaying = false; } Future triggerVibration() async { if (await Vibration.hasVibrator() ?? false) { // Vibrate continuously for 5 seconds Vibration.vibrate(duration: 5000); } } Future stopVibration() async { if (await Vibration.hasVibrator() ?? false) { Vibration.cancel(); } } Future dispose() async { await stopSound(); await stopVibration(); await _audioPlayer.dispose(); } }