Home > front end >  Preload next remote file while playing another using just_audio
Preload next remote file while playing another using just_audio

Time:08-19

I'm building a music quiz app with Flutter and just_audio. App plays one remote mp3 at a time. Then user proceeds to another screen and gets the new file. Currently, it takes some time to load file for a new screen. I'm trying to optimize and preload the next remote mp3 while playing the current one. Load method of AudioPlayer works only with current file. Same for LockCachingAudioSource class.

Is there a way to do this with just_audio? Maybe I should switch between two AudioPlayer objects or there is a better way to implement such preload?

Thank you.

CodePudding user response:

The only other mechanism to preload is ConcatenatingAudioSource but in that case the playback auto-advances to the next item, so it's not applicable to your problem.

Therefore, the correct solution is as you suspected. Have one player for the question, and a second player for the answer. Each player will maintain its own audio buffer, allowing you to preload the answer audio into the second buffer (via load() or setAudioSource(preload: true)) without affecting the first player's buffer.

  • Related