yoheimuta / RxMusicPlayer

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

Prevent a crash if user press next too fast and many times #60

Closed yoheimuta closed 2 years ago

yoheimuta commented 2 years ago

ref. https://github.com/yoheimuta/RxMusicPlayer/issues/21#issuecomment-860443895

The reproduced local log is following. I confirmed the other thread entered the play function and set the player to nil while the crashed thread tried to unwrap the player.

ready
readyToPlay
loading
RxMusicPlayer/RxMusicPlayer.swift:577: Fatal error: Unexpectedly found nil while unwrapping an Optional value
2022-06-25 12:44:43.924432+0900 ExampleSwiftUI[82068:13633583] RxMusicPlayer/RxMusicPlayer.swift:577: Fatal error: Unexpectedly found nil while unwrapping an Optional value

The play function is called within ConcurrentDispatchQueueScheduler, so it can run concurrently. It's critical to perform this blocking operation in the background thread, but it must be enough to run serially.