Fix wrong thread in throttled observers

This commit is contained in:
tzugen 2023-07-25 12:11:26 +02:00
parent fc637166bb
commit 6bc09854ac
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
2 changed files with 13 additions and 3 deletions

View File

@ -248,7 +248,10 @@ class MediaPlayerManager(
mediaControllerFuture = MediaController.Builder(
context,
sessionToken
).buildAsync()
)
// Specify mainThread explicitely
.setApplicationLooper(Looper.getMainLooper())
.buildAsync()
mediaControllerFuture?.addListener({
controller = mediaControllerFuture?.get()

View File

@ -12,6 +12,11 @@ import org.moire.ultrasonic.domain.Track
class RxBus {
/**
* IMPORTANT: methods like .delay() or .throttle() will implicitly change the thread to the
* RxComputationScheduler. Always use the function call with the additional arguments of the
* desired scheduler
**/
companion object {
fun mainThread(): Scheduler = AndroidSchedulers.mainThread()
@ -52,7 +57,8 @@ class RxBus {
playerStatePublisher
.replay(1)
.autoConnect(0)
.throttleLatest(300, TimeUnit.MILLISECONDS)
// Need to specify thread, see comment at beginning
.throttleLatest(300, TimeUnit.MILLISECONDS, mainThread())
val playlistPublisher: PublishSubject<List<Track>> =
PublishSubject.create()
@ -64,7 +70,8 @@ class RxBus {
playlistPublisher
.replay(1)
.autoConnect(0)
.throttleLatest(300, TimeUnit.MILLISECONDS)
// Need to specify thread, see comment at beginning
.throttleLatest(300, TimeUnit.MILLISECONDS, mainThread())
val trackDownloadStatePublisher: PublishSubject<TrackDownloadState> =
PublishSubject.create()