Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix episode autoplay preference having no effect #1479

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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