yoheimuta / RxMusicPlayer

A reactive library to make it easy for audio playbacks using RxSwift.
MIT License
58 stars 8 forks source link

Impossible to replace playing items #67

Closed 0xacdc closed 1 year ago

0xacdc commented 1 year ago

If I need to completely replace playing items, the only way to do this seems to be:

player.stop()

 self.player.queuedItems.enumerated().forEach { idx, value in   
      try? self.player.remove(at: idx)   
}

 self.player.append(items: newItems)

But this does not work. The remove will throw error when index will match playIndex, so if I'd like to call play(at: index_from_the_new_items) it will not be the one I want.

So, what is the solution to stop the player, replaces all items. add new ones and play from desired index ?

yoheimuta commented 1 year ago

Hi @0xacdc

Have you found a solution to replace playing items in the end?

0xacdc commented 1 year ago

HI @yoheimuta,

a solution may be:

  /**
     Clear player datasource
  */

    public func clearPlayingItems() {
        player?.pause()

        masterQueuedItems.removeAll()
        queuedItems.removeAll()
    }

but after it will need:

 private func play(atIndex index: Int) -> Observable<()> {
        if player != nil && playIndex == index && status == .paused {
            return resume()
        }
        player?.pause()

        guard queuedItems.indices.contains(index) else {
            return .just(())
        }
        ...

but because of return of empty Observable, there is no way to notify about what happened, and this is not the perfect solution

yoheimuta commented 1 year ago

@0xacdc Thanks for getting back to me. So, just to clarify, you haven't found a workaround yet, is that correct? And you closed the issue because a fix is no longer needed?

0xacdc commented 1 year ago

Yes, for the moment I switched to high priority tasks. But I think It is a important and obvious feature for any player, how to play a list of tracks, and when user is selecting another track from another playlist replace entire queue ?