How can i clear the queue of media item in audio_service
I tried updateQueue([])
to kinda reset the queue (which is not working). And why i want to do this is because i am adding mediaItem
on skipToNext like below
mediaItem.add(
MediaItem(
id: lecture.url!,
title: lecture.name!,
artUri: Uri.parse(bookArt),
artist: "artist",
album: bookName
)
);
_player.seekToNext();
and whenever i play any audio it starts from wherever i left from queue, which obviously means i have to clear out the queue. So how can i do that?
package i am using is audio_service one-isolate branch
If you follow this tutorial by Suragch. In page_manager.dart
you will see remove()
function
void remove() {
final lastIndex = _audioHandler.queue.value.length - 1;
if (lastIndex < 0) return;
_audioHandler.removeQueueItemAt(lastIndex); }
This function removes the last item from AudioService queue
and JustAudio playlist
.
So you can just loop through the playlist and call remove()
. It will clear all playlist
and queue
.
for (int i = 0; i < playlist.length; i++) {
remove();
}
Hope this answer your question!