Skip to content

Commit

Permalink
Merge pull request #29 from agufagit/master
Browse files Browse the repository at this point in the history
feat: error handling
  • Loading branch information
mehranshoqi committed Dec 14, 2023
2 parents 2f1f5f0 + 15683e3 commit 6bd1b3f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/src/voice_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class VoiceController extends MyTicker {
final Function() onComplete;
final Function() onPlaying;
final Function() onPause;
final Function(Object)? onError;
final double noiseWidth = 50.5.w();
late AnimationController animController;
final AudioPlayer _player = AudioPlayer();
Expand Down Expand Up @@ -79,6 +80,7 @@ class VoiceController extends MyTicker {
required this.onComplete,
required this.onPause,
required this.onPlaying,
this.onError,
this.randoms,
}) {
if (randoms?.isEmpty ?? true) _setRandoms();
Expand Down Expand Up @@ -107,7 +109,11 @@ class VoiceController extends MyTicker {
} catch (err) {
playStatus = PlayStatus.downloadError;
_updateUi();
rethrow;
if (onError != null) {
onError!(err);
} else {
rethrow;
}
}
}
Expand Down Expand Up @@ -259,8 +265,7 @@ class VoiceController extends MyTicker {
Future setMaxDuration(String path) async {
try {
/// get the max duration from the path or cloud
final maxDuration =
isFile ? await _player.setFilePath(path) : await _player.setUrl(path);
final maxDuration = isFile ? await _player.setFilePath(path) : await _player.setUrl(path);
if (maxDuration != null) {
this.maxDuration = maxDuration;
animController.duration = maxDuration;
Expand All @@ -270,6 +275,9 @@ class VoiceController extends MyTicker {
///
debugPrint("cant get the max duration from the path $path");
}
if (onError != null) {
onError!(err);
}
}
}
}
Expand Down

0 comments on commit 6bd1b3f

Please sign in to comment.