feat(audio): 引入audioplayers原生提示音效,修复做完提示音缺失与局域网配置溢出
This commit is contained in:
@@ -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 (_) {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user