diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerManager.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerManager.kt index 2a4cbbdc..93588750 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerManager.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerManager.kt @@ -248,7 +248,10 @@ class MediaPlayerManager( mediaControllerFuture = MediaController.Builder( context, sessionToken - ).buildAsync() + ) + // Specify mainThread explicitely + .setApplicationLooper(Looper.getMainLooper()) + .buildAsync() mediaControllerFuture?.addListener({ controller = mediaControllerFuture?.get() diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RxBus.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RxBus.kt index 9912cf0d..8524fdff 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RxBus.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RxBus.kt @@ -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> = 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 = PublishSubject.create()