From 9cdba9a27a48219d72f316cbc921325ca9cb51dc Mon Sep 17 00:00:00 2001 From: tzugen Date: Thu, 21 Apr 2022 14:42:24 +0200 Subject: [PATCH] Ensure main thread usage in Rx subscription. --- .../org/moire/ultrasonic/fragment/PlayerFragment.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/PlayerFragment.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/PlayerFragment.kt index 785ccd19..bb06c722 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/PlayerFragment.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/PlayerFragment.kt @@ -393,13 +393,18 @@ class PlayerFragment : } // Observe playlist changes and update the UI - // FIXME rxBusSubscription += RxBus.playlistObservable.subscribe { - onPlaylistChanged() + // Use launch to ensure running it in the main thread + launch { + onPlaylistChanged() + } } rxBusSubscription += RxBus.playerStateObservable.subscribe { - update() + // Use launch to ensure running it in the main thread + launch { + update() + } } mediaPlayerController.controller?.addListener(object : Player.Listener {