tetraq/lib/services/audio_service.dart

64 lines
1.9 KiB
Dart
Raw Normal View History

2026-03-01 20:59:06 +01:00
// ===========================================================================
// FILE: lib/services/audio_service.dart
// ===========================================================================
2026-02-27 23:35:54 +01:00
import 'package:flutter/material.dart';
import 'package:audioplayers/audioplayers.dart';
import '../core/app_colors.dart';
class AudioService extends ChangeNotifier {
static final AudioService instance = AudioService._internal();
AudioService._internal();
bool isMuted = false;
final AudioPlayer _sfxPlayer = AudioPlayer();
void toggleMute() {
isMuted = !isMuted;
notifyListeners();
}
void playLineSfx(AppThemeType theme) async {
if (isMuted) return;
String file = '';
switch (theme) {
2026-03-01 20:59:06 +01:00
case AppThemeType.minimal:
case AppThemeType.arcade: // Suono secco per l'arcade
file = 'minimal_line.wav'; break;
2026-02-27 23:35:54 +01:00
case AppThemeType.doodle:
case AppThemeType.wood:
file = 'doodle_line.wav'; break;
2026-03-01 20:59:06 +01:00
case AppThemeType.cyberpunk:
case AppThemeType.grimorio: // Suono etereo per la magia
file = 'cyber_line.wav'; break;
2026-02-27 23:35:54 +01:00
}
await _sfxPlayer.play(AssetSource('audio/sfx/$file'));
}
void playBoxSfx(AppThemeType theme) async {
if (isMuted) return;
String file = '';
switch (theme) {
2026-03-01 20:59:06 +01:00
case AppThemeType.minimal:
case AppThemeType.arcade:
file = 'minimal_box.wav'; break;
2026-02-27 23:35:54 +01:00
case AppThemeType.doodle:
case AppThemeType.wood:
file = 'doodle_box.wav'; break;
2026-03-01 20:59:06 +01:00
case AppThemeType.cyberpunk:
case AppThemeType.grimorio:
file = 'cyber_box.wav'; break;
2026-02-27 23:35:54 +01:00
}
await _sfxPlayer.play(AssetSource('audio/sfx/$file'));
}
void playBonusSfx() async {
if (isMuted) return;
await _sfxPlayer.play(AssetSource('audio/sfx/bonus.wav'));
}
void playBombSfx() async {
if (isMuted) return;
await _sfxPlayer.play(AssetSource('audio/sfx/bomb.wav'));
}
}