Reputation: 773
I'm trying to make a music app using just_audio and audio_service and I'm stuck at implementing the onAddQueueItem
function. I can't find a way to append/modify the queue on just_audio, only how to reload just_audio with a new playlist via player.setAudioSource
.
Am I meant to use player.setAudioSource
to change the current queue or am I missing something?
Upvotes: 2
Views: 2601
Reputation: 2786
Queues/playlists are achieved in just_audio by creating a ConcatenatingAudioSource
which gives a list of audio sources to be played one after the other. The documentation for that class lists the methods below, almost all of which deal with appending/modifying the queue:
So the one you want when implementing onAddQueueItem
is the first one, add
:
Future<void> onAddQueueItem(MediaItem mediaItem) async {
// Add it to the player
await concatenatingAudioSource.add(AudioSource.uri(Uri.parse(mediaItem.id)));
// Broadcast the state change to clients
queue.add(mediaItem);
await AudioServiceBackground.setQueue(queue);
}
Upvotes: 2