import 'package:just_audio/just_audio.dart'; import 'package:flutter/services.dart'; import 'package:vibration/vibration.dart'; class AudioManager { static final AudioManager _instance = AudioManager._internal(); factory AudioManager() => _instance; AudioManager._internal(); final AudioPlayer _backgroundPlayer = AudioPlayer(); final AudioPlayer _effectPlayer = AudioPlayer(); bool _soundEnabled = true; bool _musicEnabled = true; bool _hapticEnabled = true; bool get soundEnabled => _soundEnabled; bool get musicEnabled => _musicEnabled; bool get hapticEnabled => _hapticEnabled; Future initialize() async { try { // Set up background music loop await _backgroundPlayer.setLoopMode(LoopMode.one); // For now, we'll use system sounds. In production, we'd load actual audio files // await _backgroundPlayer.setAsset('assets/audio/background_ambient.mp3'); } catch (e) { print('Audio initialization failed: $e'); } } Future playBubblePop() async { if (!_soundEnabled) return; try { // Play system click sound as placeholder await SystemSound.play(SystemSoundType.click); // Add haptic feedback if (_hapticEnabled) { await _playHapticFeedback(); } } catch (e) { print('Failed to play bubble pop sound: $e'); } } Future playBackgroundMusic() async { if (!_musicEnabled) return; try { // For now, we'll skip background music until we have audio files // await _backgroundPlayer.play(); print('Background music would play here'); } catch (e) { print('Failed to play background music: $e'); } } Future stopBackgroundMusic() async { try { await _backgroundPlayer.stop(); } catch (e) { print('Failed to stop background music: $e'); } } Future pauseBackgroundMusic() async { try { await _backgroundPlayer.pause(); } catch (e) { print('Failed to pause background music: $e'); } } Future resumeBackgroundMusic() async { if (!_musicEnabled) return; try { await _backgroundPlayer.play(); } catch (e) { print('Failed to resume background music: $e'); } } Future _playHapticFeedback() async { try { if (await Vibration.hasVibrator() ?? false) { await Vibration.vibrate(duration: 50); } } catch (e) { print('Failed to play haptic feedback: $e'); } } void setSoundEnabled(bool enabled) { _soundEnabled = enabled; } void setMusicEnabled(bool enabled) { _musicEnabled = enabled; if (!enabled) { stopBackgroundMusic(); } else { playBackgroundMusic(); } } void setHapticEnabled(bool enabled) { _hapticEnabled = enabled; } Future dispose() async { await _backgroundPlayer.dispose(); await _effectPlayer.dispose(); } }