Currently i am working on music app and according to my ui i have to manage audio player with carousel slider.The without carousel slider it is working fine but with carousel slider when click on the shuffle or when onPageChanged called, i used the skipToQueueItem for play particular song with audio player, that time suddenly audioHandler.mediaItem listen continuously called and in every 1 second changed song and slider images because of skipToQueueItem line.I used just audio and audio service package.For privacy i am not sharing the code.But for update carousel slider with audio i used below code.
audioHandler.queue.listen((playlist) async {
if (playlist.isEmpty) {
mediaItemsListNotifier.value = [];
} else {
///Update media items notifier list value
mediaItemsListNotifier.value = playlist;
await audioHandler.updateQueue(playlist);
}
});
audioHandler.mediaItem.listen((mediaItem) async {
int index = audioHandler.queue.value.indexOf(mediaItem!);
currentSliderIndex.value = index >= 0 ? index : 0;
///Main issue using this line
await audioHandle.skipToQueueItem(currentSliderIndex.value);
carouselController.jumpToPage(currentSliderIndex.value);
}