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:
