最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

flutter - Just Audio playlist stop the audio when loading the next element - Stack Overflow

programmeradmin4浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论