Automatic refresh rate switching setting (#382)

Adds an advanced playback setting to enable automatic refresh rate
switching during playback

When enabled, the app looks at the available display modes, chooses the
best candidate, and attempts to switch to it. After playback ends, the
display is switched back to the original mode.

Closes #62
Closes #379
This commit is contained in:
damontecres 2025-12-06 16:35:43 -05:00 committed by GitHub
parent e669f3ad59
commit 20bef8fb6a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 176 additions and 3 deletions

View file

@ -42,6 +42,7 @@ import com.github.damontecres.wholphin.services.NavigationManager
import com.github.damontecres.wholphin.services.PlayerFactory
import com.github.damontecres.wholphin.services.PlaylistCreationResult
import com.github.damontecres.wholphin.services.PlaylistCreator
import com.github.damontecres.wholphin.services.RefreshRateService
import com.github.damontecres.wholphin.ui.launchIO
import com.github.damontecres.wholphin.ui.nav.Destination
import com.github.damontecres.wholphin.ui.onMain
@ -121,6 +122,7 @@ class PlaybackViewModel
private val datePlayedService: DatePlayedService,
private val deviceInfo: DeviceInfo,
private val deviceProfileService: DeviceProfileService,
private val refreshRateService: RefreshRateService,
) : ViewModel(),
Player.Listener,
AnalyticsListener {
@ -184,6 +186,9 @@ class PlaybackViewModel
) {
nextUp.value = null
this.preferences = preferences
if (preferences.appPreferences.playbackPreferences.refreshRateSwitching) {
addCloseable { refreshRateService.resetRefreshRate() }
}
controllerViewState.hideMilliseconds =
preferences.appPreferences.playbackPreferences.controllerTimeoutMs
this.forceTranscoding =
@ -611,6 +616,11 @@ class PlaybackViewModel
}
}
if (preferences.appPreferences.playbackPreferences.refreshRateSwitching) {
source.mediaStreams?.firstOrNull { it.type == MediaStreamType.VIDEO }?.let {
refreshRateService.changeRefreshRate(it)
}
}
withContext(Dispatchers.Main) {
// TODO, don't need to release & recreate when switching streams
this@PlaybackViewModel.activityListener?.let {