yoheimuta / RxMusicPlayer

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

Add MP3 Urls by Button while playing #28

Closed StefaniOSApps closed 2 years ago

StefaniOSApps commented 3 years ago

How can I add a mp3 url by button, if the player plays - without seek difference?

my solution

fileUrlRelay
  .skip(1)
  .distinctUntilChanged()
  .compactMap({ $0 })
  .map({ DownloadHelper.storedUrl(url: $0) ?? $0 })
  .map({ RxMusicPlayerItem(url: $0, meta: .init()) })
  .map({ [$0] })
  .bind(to: player.queuedItemsRelay)
  .disposed(by: bag)

but I can not access to queuedItemsRelay.

yoheimuta commented 3 years ago

@StefaniOSApps Thank you for reaching out.

Since the previous version only supports appending items, I added new features of inserting and removing an item at the specified location.

Can you confirm it works?

StefaniOSApps commented 3 years ago

@yoheimuta thanks for this vid. Imagine that you are playing a 10 min song in English. then you open a menu and change the language to e.g. Turkish. My wish is that it plays the other language at the same time. So English stops at 5:33 and Turkish continues from 5:34. i have implemented a solution but this is only a workaround. In addition, there is the lack of error handling if the URL is not reachable.

there is a list of URLs that are played. however, the list may change for future titles. This is the case when a language change takes place.

yoheimuta commented 3 years ago

@StefaniOSApps Thank you for your additional information. First of all, the new APIs of inserting/removing an item from the playlist can modify queuedItemsRelay safely.

To change the item while keeping its playback time position sequential, it seems like you can use the current APIs like below:

  1. Insert the Turkish version song at the next position
  2. Play the next one by sending the next command
  3. Seek it to the desired second(5:34)
  4. Remove the English version song at the previous position

At least, this flow can handle errors as far as you refer to the example code. Adding a new API like playNextSeekTo to combine 2 and 3 would work for a more smooth transition.