Skip to content

Commit

Permalink
fix(web): make start and resume async (#1436)
Browse files Browse the repository at this point in the history
If playing an invalid file (e.g. an empty file), the error is not
propagated back to the library, as the error is thrown when starting the
`play` / `resume` operation.
This ensures that the future of web js `play` is awaited.
  • Loading branch information
Gustl22 authored Mar 17, 2023
1 parent 82f16c3 commit b95bc8f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/audioplayers_web/lib/audioplayers_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class AudioplayersPlugin extends AudioplayersPlatform with StreamsInterface {

@override
Future<void> resume(String playerId) async {
getOrCreatePlayer(playerId).resume();
await getOrCreatePlayer(playerId).resume();
}

@override
Expand Down
8 changes: 4 additions & 4 deletions packages/audioplayers_web/lib/wrapped_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,20 @@ class WrappedPlayer {
playerPlaySubscription = null;
}

void start(double position) {
Future<void> start(double position) async {
isPlaying = true;
if (currentUrl == null) {
return; // nothing to play yet
}
if (player == null) {
recreateNode();
}
player?.play();
await player?.play();
player?.currentTime = position;
}

void resume() {
start(pausedAt ?? 0);
Future<void> resume() async {
await start(pausedAt ?? 0);
}

void pause() {
Expand Down

0 comments on commit b95bc8f

Please sign in to comment.