From 8eb5026f32fc81c3fe26f87052fa5d899953f39b Mon Sep 17 00:00:00 2001 From: Luca Franke <84925848+lfranke42@users.noreply.github.com> Date: Sat, 14 Sep 2024 02:49:49 +0200 Subject: [PATCH] Fix episode autoplay preference having no effect (#1479) add check for user auto play setting --- .../org/jellyfin/mobile/player/PlayerViewModel.kt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/jellyfin/mobile/player/PlayerViewModel.kt b/app/src/main/java/org/jellyfin/mobile/player/PlayerViewModel.kt index e3306fa47..4c6b3c6d5 100644 --- a/app/src/main/java/org/jellyfin/mobile/player/PlayerViewModel.kt +++ b/app/src/main/java/org/jellyfin/mobile/player/PlayerViewModel.kt @@ -60,9 +60,11 @@ import org.jellyfin.sdk.api.client.exception.ApiClientException import org.jellyfin.sdk.api.client.extensions.displayPreferencesApi import org.jellyfin.sdk.api.client.extensions.hlsSegmentApi import org.jellyfin.sdk.api.client.extensions.playStateApi +import org.jellyfin.sdk.api.client.extensions.userApi import org.jellyfin.sdk.api.operations.DisplayPreferencesApi import org.jellyfin.sdk.api.operations.HlsSegmentApi import org.jellyfin.sdk.api.operations.PlayStateApi +import org.jellyfin.sdk.api.operations.UserApi import org.jellyfin.sdk.model.api.PlayMethod import org.jellyfin.sdk.model.api.PlaybackProgressInfo import org.jellyfin.sdk.model.api.PlaybackStartInfo @@ -81,6 +83,7 @@ class PlayerViewModel(application: Application) : AndroidViewModel(application), private val displayPreferencesApi: DisplayPreferencesApi = apiClient.displayPreferencesApi private val playStateApi: PlayStateApi = apiClient.playStateApi private val hlsSegmentApi: HlsSegmentApi = apiClient.hlsSegmentApi + private val userApi: UserApi = apiClient.userApi private val lifecycleObserver = PlayerLifecycleObserver(this) private val audioManager: AudioManager by lazy { getApplication().getSystemService()!! } @@ -132,6 +135,7 @@ class PlayerViewModel(application: Application) : AndroidViewModel(application), private val mediaSessionCallback = PlayerMediaSessionCallback(this) private var displayPreferences = DisplayPreferences() + private var autoPlayNextEpisodeEnabled: Boolean = false init { ProcessLifecycleOwner.get().lifecycle.addObserver(lifecycleObserver) @@ -157,6 +161,15 @@ class PlayerViewModel(application: Application) : AndroidViewModel(application), } } + viewModelScope.launch { + try { + val userConfig = userApi.getCurrentUser().content.configuration + autoPlayNextEpisodeEnabled = userConfig?.enableNextEpisodeAutoPlay ?: false + } catch (e: ApiClientException) { + Timber.e(e, "Failed to load auto play preference") + } + } + // Subscribe to player events from webapp viewModelScope.launch { for (event in playerEventChannel) { @@ -517,7 +530,7 @@ class PlayerViewModel(application: Application) : AndroidViewModel(application), } Player.STATE_ENDED -> { reportPlaybackStop() - if (!queueManager.next()) { + if (!autoPlayNextEpisodeEnabled || !queueManager.next()) { releasePlayer() } }