Skip to content

Commit

Permalink
Fix episode autoplay preference having no effect (#1479)
Browse files Browse the repository at this point in the history
add check for user auto play setting
  • Loading branch information
lfranke42 authored Sep 14, 2024
1 parent 0182f3a commit 8eb5026
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion app/src/main/java/org/jellyfin/mobile/player/PlayerViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Application>().getSystemService()!! }
Expand Down Expand Up @@ -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)
Expand All @@ -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) {
Expand Down Expand Up @@ -517,7 +530,7 @@ class PlayerViewModel(application: Application) : AndroidViewModel(application),
}
Player.STATE_ENDED -> {
reportPlaybackStop()
if (!queueManager.next()) {
if (!autoPlayNextEpisodeEnabled || !queueManager.next()) {
releasePlayer()
}
}
Expand Down

0 comments on commit 8eb5026

Please sign in to comment.