suragch / flutter_audio_service_demo

Companion project for Flutter audio_service tutorial
https://suragch.medium.com/background-audio-in-flutter-with-audio-service-and-just-audio-3cce17b4a7d?sk=0837a1b1773e27a4f879ff3072e90305
MIT License
57 stars 28 forks source link

MediaItem and IndexedAudioSource aren't in sync in shuffleMode #19

Closed AssassinAguilar closed 2 years ago

AssassinAguilar commented 2 years ago

Hello Sir, I have completely followed your tutorial and I am still having problem in syncing MediaItem and IndexedAudioSource like some song is playing and my app shows details of some other song in shuffle mode.

erayhaydar commented 2 years ago

Hi @AssassinAguilar, I have the same problem. How did you fix it ?

erayhaydar commented 2 years ago

I found the problem, change this functions like that.

image

AssassinAguilar commented 2 years ago

Hi @erayhaydar, I have switched to the official tutorial of audio_service in https://github.com/ryanheise/audio_service/blob/minor/audio_service/example/lib/example_playlist.dart and if you want to add duration later rather than in mediaItem change the current song function with

Rx.combineLatest5<int?, List<MediaItem>, bool, List<int>?, Duration?,
                MediaItem?>(
            _player.currentIndexStream,
            queue,
            _player.shuffleModeEnabledStream,
            _player.shuffleIndicesStream,
            _player.durationStream,
            (index, queue, shuffleModeEnabled, shuffleIndices, duration) {
      final queueIndex =
          getQueueIndex(index, shuffleModeEnabled, shuffleIndices);
      return (queueIndex != null && queueIndex < queue.length)
          ? queue[queueIndex].copyWith(duration: duration)
          : null;
    })
        .debounceTime(const Duration(milliseconds: 750))
        .whereType<MediaItem>()
        .distinct()
        .listen(mediaItem.add);
erayhaydar commented 2 years ago

@AssassinAguilar Thank you!