I am building an Android app with flutter and just audio. My goal is to play looped sounds to the user and go to next one when the user click on a button.
To do that I have a player and a playlist, I get the sounds on a server (for example ):
final _playlist = ConcatenatingAudioSource(children: [...]);
final AudioPlayer _player = AudioPlayer();
...
_player.setAudioSource(_playlist);
_player.setLoopMode(LoopMode.all);
...
// Go to next sound
_player.seekToNext();
Everything is working fine except when I select the next sound in the playlist before it's loaded.
The behavour I want is that the playing sound stops, and when the next is loaded it starts playing again.
What I get when calling _player.seekToNext()
is that the playing sound plays until the next is loaded and starts.
I tried to pause the player and plays after waiting to the next sound to be loaded, be the await seems stuck forever when the player is paused (sound stops but never start again):
_player.pause();
await _player.seekToNext();
_player.play(); // Never executed
My flutter version is 3.24.5 and just_audio 0.9.46.
Maybe the playlist isn't the rigth tool for my use case, I am thinking about having two players, one playing the sound, and one loading the next.