feat(audio): 引入audioplayers原生提示音效,修复做完提示音缺失与局域网配置溢出

This commit is contained in:
shen
2026-10-27 04:20:18 -07:00
parent 473fbb93ad
commit 1f794585cd
14 changed files with 289 additions and 13 deletions
+42
View File
@@ -0,0 +1,42 @@
import 'package:audioplayers/audioplayers.dart';
import 'package:flutter/foundation.dart';
class AudioService {
static final AudioService _instance = AudioService._internal();
factory AudioService() => _instance;
AudioService._internal();
final AudioPlayer _player = AudioPlayer();
Future<void> init() async {
try {
await _player.setReleaseMode(ReleaseMode.stop);
} catch (e) {
debugPrint('AudioService init error: $e');
}
}
Future<void> playStepComplete() async {
try {
await _player.stop();
await _player.play(AssetSource('audio/step_complete.wav'));
} catch (e) {
debugPrint('Error playing step_complete: $e');
}
}
Future<void> playSessionComplete() async {
try {
await _player.stop();
await _player.play(AssetSource('audio/session_complete.wav'));
} catch (e) {
debugPrint('Error playing session_complete: $e');
}
}
Future<void> dispose() async {
try {
await _player.dispose();
} catch (_) {}
}
}