43 lines
1.0 KiB
Dart
43 lines
1.0 KiB
Dart
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 (_) {}
|
|
}
|
|
}
|