Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include MediaItem duration auto update as default for playlist example #1093

Open
pablodemergelina opened this issue Sep 28, 2024 · 1 comment

Comments

@pablodemergelina
Copy link

Documentation request for the following page(s)

Rx.combineLatest4<int?, List<MediaItem>, bool, List<int>?, MediaItem?>(

Section(s) in question

// Broadcast media item changes.
Rx.combineLatest4<int?, List<MediaItem>, bool, List<int>?, MediaItem?>(
    _player.currentIndexStream,
    queue,
    _player.shuffleModeEnabledStream,
    _player.shuffleIndicesStream,
    (index, queue, shuffleModeEnabled, shuffleIndices) {
  final queueIndex =
      getQueueIndex(index, shuffleModeEnabled, shuffleIndices);
  return (queueIndex != null && queueIndex < queue.length)
      ? queue[queueIndex]
      : null;
}).whereType<MediaItem>().distinct().listen(mediaItem.add);

Suggested improvement

Really usefull Stackoverflow answer https://stackoverflow.com/questions/69346791/how-to-get-the-audio-file-url-total-duration-using-audio-service-package by Sho in order to get MediaItems duration automatically when loading audio. This can be included as default on example_playlist or a least a comment explaining or referencing Stackoverflow answer.

// Broadcast media item changes.
Rx.combineLatest5<int?, List<MediaItem>, bool, List<int>?, Duration?, MediaItem?>( // <- add duration
    _player.currentIndexStream,
    queue,
    _player.shuffleModeEnabledStream,
    _player.shuffleIndicesStream,
    _player.durationStream, // <- add listening to durationStream here
    (index, queue, shuffleModeEnabled, shuffleIndices, duration) {
  final queueIndex =
      getQueueIndex(index, shuffleModeEnabled, shuffleIndices);
  return (queueIndex != null && queueIndex < queue.length)
      ? queue[queueIndex].copyWith(duration: duration) // <- sink mediaItem provided with duration
      : null;
}).whereType<MediaItem>().distinct().listen(mediaItem.add);
@muhammadkamel
Copy link

Please, note that the distinct method, prevent updating the duration for the selected item.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants