2

I use the plugin just_audio How can I continu my music after to do a pause? please.

void _play() {
    audioPlayer.setAsset("assets/applause.mp3");
    audioPlayer.play();
  }
void _pause() async {
    await audioPlayer.pause();
  }
  void _rePlay() async {
    ?????????????????????????
  }
Carle
  • 25
  • 6

2 Answers2

3

In general, after calling pause, call play to "resume".

In your case, you should NOT set the asset file again. This resets the process.

Below is your code, pasted from your question:

void _play() { // BAD EXAMPLE
  audioPlayer.setAsset("assets/applause.mp3"); // <-- PROBLEM
  audioPlayer.play();
}

You should move setAsset call elsewhere, like in init state.

WSBT
  • 33,033
  • 18
  • 128
  • 133
0

You can just call audioPlayer.play(). This works exactly like the play button in a music app, while pause() works exactly like the pause button in a music app.

It is designed this way so that you can simply wire up your play and pause buttons directly to these player methods.

For example, here are the play/pause buttons from the just_audio example app:

// Play button:
IconButton(
  icon: Icon(Icons.play_arrow),
  onPressed: audioPlayer.play,
)
// Pause button:
IconButton(
  icon: Icon(Icons.pause),
  onPressed: audioPlayer.pause,
)

You can just alternate calls to play()/pause()/play()/pause(). Note the left side of this state diagram from the README:

enter image description here

Ryan Heise
  • 2,273
  • 5
  • 14