Merge remote boxing module (one2one, one2many, many2one modes) with local sound and vibration feedback feature. Migrate SharedPreferences to AppConfigService across all services including SoundService. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
59 lines
1.4 KiB
Dart
59 lines
1.4 KiB
Dart
import 'package:audioplayers/audioplayers.dart';
|
|
import 'package:pad_scanner/services/app_config_service.dart';
|
|
|
|
class SoundService {
|
|
static const _keySuccess = 'sound_success';
|
|
static const _keyFailure = 'sound_failure';
|
|
|
|
final _player = AudioPlayer();
|
|
final _configService = AppConfigService();
|
|
|
|
Future<String?> getSuccessPath() async {
|
|
return _configService.getString(_keySuccess);
|
|
}
|
|
|
|
Future<String?> getFailurePath() async {
|
|
return _configService.getString(_keyFailure);
|
|
}
|
|
|
|
Future<void> setSuccessPath(String? path) async {
|
|
if (path != null) {
|
|
await _configService.setString(_keySuccess, path);
|
|
} else {
|
|
final config = await _configService.loadConfig();
|
|
config.remove(_keySuccess);
|
|
}
|
|
}
|
|
|
|
Future<void> setFailurePath(String? path) async {
|
|
if (path != null) {
|
|
await _configService.setString(_keyFailure, path);
|
|
} else {
|
|
final config = await _configService.loadConfig();
|
|
config.remove(_keyFailure);
|
|
}
|
|
}
|
|
|
|
Future<void> playSuccess() async {
|
|
final path = await getSuccessPath();
|
|
if (path != null) {
|
|
await _player.play(DeviceFileSource(path));
|
|
}
|
|
}
|
|
|
|
Future<void> playFailure() async {
|
|
final path = await getFailurePath();
|
|
if (path != null) {
|
|
await _player.play(DeviceFileSource(path));
|
|
}
|
|
}
|
|
|
|
Future<void> play(String path) async {
|
|
await _player.play(DeviceFileSource(path));
|
|
}
|
|
|
|
Future<void> dispose() async {
|
|
await _player.dispose();
|
|
}
|
|
}
|