import 'package:flutter/services.dart'; import 'package:audioplayers/audioplayers.dart'; import 'package:em2rp/utils/debug_log.dart'; /// Service pour émettre des feedbacks sonores lors des interactions class AudioFeedbackService { static final AudioPlayer _player = AudioPlayer(); /// Jouer un son de succès static Future playSuccessBeep() async { try { // Jouer un son système await HapticFeedback.mediumImpact(); await SystemSound.play(SystemSoundType.click); // Alternative : jouer un son personnalisé si disponible // await _player.play(AssetSource('sounds/success.mp3')); } catch (e) { DebugLog.error('[AudioFeedbackService] Error playing success beep', e); } } /// Jouer un son d'erreur static Future playErrorBeep() async { try { // Double bip pour indiquer une erreur await HapticFeedback.heavyImpact(); await SystemSound.play(SystemSoundType.click); await Future.delayed(const Duration(milliseconds: 100)); await SystemSound.play(SystemSoundType.click); // Alternative : jouer un son d'erreur personnalisé si disponible // await _player.play(AssetSource('sounds/error.mp3')); } catch (e) { DebugLog.error('[AudioFeedbackService] Error playing error beep', e); } } /// Jouer une vibration haptique (si disponible) static Future playHapticFeedback() async { try { await HapticFeedback.mediumImpact(); } catch (e) { DebugLog.error('[AudioFeedbackService] Error playing haptic feedback', e); } } /// Jouer un feedback complet (son + vibration) static Future playFullFeedback({bool isSuccess = true}) async { if (isSuccess) { await playSuccessBeep(); } else { await playErrorBeep(); } } /// Nettoyer les ressources static Future dispose() async { await _player.dispose(); } }