From eab55a78376d219334da3240d60339a79d46e59f Mon Sep 17 00:00:00 2001 From: Alex Katlein Date: Mon, 24 Jul 2023 17:43:03 +0000 Subject: [PATCH] Apply 1 suggestion(s) to 1 file(s) --- .../ultrasonic/service/MediaPlayerManager.kt | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) 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 cbeb167d..8ee3792f 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerManager.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerManager.kt @@ -181,22 +181,23 @@ class MediaPlayerManager( createMediaController(onCreated) - rxBusSubscription += RxBus.activeServerChangingObservable.subscribe { oldServer -> - // Even though Rx should launch on the main thread it doesn't always :( - mainScope.launch { - if (oldServer != OFFLINE_DB_ID) { - // When the server changes, the playlist can retain the downloaded songs. - // Incomplete songs should be removed as the new server won't recognise them. - removeIncompleteTracksFromPlaylist() - DownloadService.requestStop() + rxBusSubscription += + RxBus + .activeServerChangingObservable + .subscribeOn(AndroidSchedulers.mainThread()) + .subscribe { oldServer -> + if (oldServer != OFFLINE_DB_ID) { + // When the server changes, the playlist can retain the downloaded songs. + // Incomplete songs should be removed as the new server won't recognise them. + removeIncompleteTracksFromPlaylist() + DownloadService.requestStop() + } + if (controller is JukeboxMediaPlayer) { + // When the server changes, the Jukebox should be released. + // The new server won't understand the jukebox requests of the old one. + switchToLocalPlayer() + } } - if (controller is JukeboxMediaPlayer) { - // When the server changes, the Jukebox should be released. - // The new server won't understand the jukebox requests of the old one. - switchToLocalPlayer() - } - } - } rxBusSubscription += RxBus.activeServerChangedObservable.subscribe { val jukebox = activeServerProvider.getActiveServer().jukeboxByDefault