play method
Implementation
Future<void> play(String filePath, {VoidCallback? onComplete}) async {
try {
_isPaused = false;
if (_currentPath == filePath && isPlaying) {
await stop();
return;
}
if (isPlaying) {
await stop();
}
_onComplete = onComplete;
_currentPath = filePath;
await _player.setFilePath(filePath);
_player.playerStateStream.listen((state) {
if (state.processingState == just_audio.ProcessingState.completed) {
_onComplete?.call();
}
});
await _player.play();
} catch (e) {
debugPrint('play failed: $e');
rethrow;
}
}