Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6ad4de4
fix(player): time Up Next from the end of the file, not the credits m…
Rhainland Nov 18, 2026
445ca87
fix(tv): keep returning the series page to the next episode from the …
Rhainland Nov 18, 2026
9a0ef16
feat(player): let viewers turn Next Up off
Rhainland Nov 18, 2026
fa22e02
fix(settings): make a Show Next Up time this device's whole choice
Rhainland Nov 18, 2026
4c481a2
fix(tv): leave a hand-opened Up Next without a countdown at the promp…
Quick104 Nov 19, 2026
c693acd
Merge branch 'review/fix-994' into review/fix-995
Quick104 Nov 19, 2026
85cf2c3
fix(player): keep a Show Next Up time and the final position when Off…
Quick104 Nov 19, 2026
f6fdb38
Merge branch 'main' into feat/next-up-off
Quick104 Nov 23, 2026
de577ed
fix(player): arm no Up Next once Next Up is off while the next episod…
Quick104 Nov 23, 2026
966f8d8
Merge main into feat/next-up-off
Quick104 Nov 24, 2026
635f5ec
chore(settings): re-vendor the settings contract from silo-server#450…
Quick104 Nov 24, 2026
3927ac8
fix(settings): drop the Next Up override marker a server without the …
Quick104 Nov 24, 2026
b48f48b
fix(player): honor Next Up Off in picture-in-picture and on a running…
Quick104 Nov 24, 2026
41e4931
fix(player): leave the player when the last thing holding it open aft…
Quick104 Nov 24, 2026
31647af
fix(player): close when Next Up turns off while the end screen waits …
Quick104 Nov 24, 2026
33ac5cb
fix(player): close when Next Up turns off while an automatic end card…
Quick104 Nov 24, 2026
67d1743
fix(player): clear an automatic Up Next card when Next Up turns off b…
Quick104 Nov 24, 2026
3bea593
fix(player): judge the end of playback by position as well as the end…
Quick104 Nov 24, 2026
7b762e7
fix(player): keep resumed playback open when Next Up turns off after …
Quick104 Nov 24, 2026
bb46caf
fix(player): forget the end when the system media controls seek away …
Quick104 Nov 24, 2026
9f9d2ae
test(tv): cover Next Up Off while the next-episode lookup waits
Quick104 Nov 24, 2026
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
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ class FileDiagnosticsBundleBuilder : DiagnosticsBundleBuilder {
"catalog.metadata_language", "playback.audio_language", "playback.auto_play_next",
"playback.auto_play_next_preview", "playback.auto_skip_credits", "playback.auto_skip_intro",
"playback.auto_skip_recap", "playback.buffering_quality_mode", "playback.intro_skip_mode",
"playback.max_bitrate_kbps", "playback.next_up_prompt_seconds",
"playback.max_bitrate_kbps", "playback.next_up_enabled", "playback.next_up_prompt_seconds",
"playback.preferred_quality", "playback.show_forced_subtitles", "playback.subtitle_appearance",
"playback.subtitle_language", "playback.subtitle_mode", "player.audio_sync_ms",
"player.dolby_vision_enabled", "player.dv_profile7_hdr10_fallback", "player.hdr_enabled",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,18 +268,21 @@ class AndroidPlayerSettingsStore(
}

/**
* Whether the active server's manifest defines
* `playback.buffering_quality_mode`: null until its manifest is read.
* Whether the active server's manifest defines [key], one of
* [PlaybackSettingsKeys.ManifestDetectedKeys]: null until its manifest is read.
*/
private val bufferingQualityModeDefined: Flow<Boolean?> =
private fun manifestDefines(key: String): Flow<Boolean?> =
if (contractRevision == null) {
flowOf(true)
} else {
combine(currentScopeFlow, contractRevision.known) { scope, _ ->
scope?.let { contractRevision.stores(it.serverUrl, PlaybackSettingsKeys.BufferingQualityMode) }
scope?.let { contractRevision.stores(it.serverUrl, key) }
}.distinctUntilChanged()
}

private val bufferingQualityModeDefined: Flow<Boolean?> =
manifestDefines(PlaybackSettingsKeys.BufferingQualityMode)

// No legacy boolean behind this one: an absent or unknown value is the
// contract default. Until the server's manifest is read, the last mode
// seen here applies; a server without the setting plays the default, and
Expand All @@ -297,6 +300,21 @@ class AndroidPlayerSettingsStore(
override val bufferingQualityModeSupportedFlow: Flow<Boolean> =
bufferingQualityModeDefined.map { it == true }.distinctUntilChanged()

private val nextUpEnabledDefined: Flow<Boolean?> =
manifestDefines(PlaybackSettingsKeys.NextUpEnabled)

// As with the buffering mode: until the manifest is read the last choice
// seen applies, and a server without the setting keeps Next Up on.
override val nextUpEnabledFlow: Flow<Boolean> =
combine(
profileScopedFlow(true) { p, s -> p.boolFor(s, PlaybackSettingsKeys.NextUpEnabled, true) },
nextUpEnabledDefined,
) { enabled, defined -> enabled || defined == false }
.distinctUntilChanged()

override val nextUpEnabledSupportedFlow: Flow<Boolean> =
nextUpEnabledDefined.map { it == true }.distinctUntilChanged()

// ---- Booleans ------------------------------------------------------
override val autoSkipCreditsFlow: Flow<Boolean> =
profileScopedFlow(false) { p, s -> p.boolFor(s, PlaybackSettingsKeys.AutoSkipCredits, false) }
Expand Down Expand Up @@ -525,22 +543,10 @@ class AndroidPlayerSettingsStore(

/**
* Settings offers this only while the server's manifest defines the key
* ([bufferingQualityModeSupportedFlow]). Like [setCellularQuality] it is
* marked unconfirmed, so a write the flusher held while the manifest was
* unknown is sent again by the first refresh rather than replaced with
* the server's default.
* ([bufferingQualityModeSupportedFlow]); [writeString] marks it unconfirmed.
*/
override suspend fun setBufferingQualityMode(value: BufferingQualityMode) {
val key = PlaybackSettingsKeys.BufferingQualityMode
withScope { scope, store ->
store.edit {
it[stringPreferencesKey(scope.keyPrefix + key)] = value.wireValue
markDeviceOverride(it, scope, key)
it[unconfirmedKeysKey(scope)] = it[unconfirmedKeysKey(scope)].orEmpty() + key
}
serverSettingsFlusher.enqueue(scope.profileId, key, value.wireValue, scope.serverUrl, scope.authority)
}
}
override suspend fun setBufferingQualityMode(value: BufferingQualityMode) =
writeString(PlaybackSettingsKeys.BufferingQualityMode, value.wireValue)

override suspend fun setAutoSkipCredits(value: Boolean) =
writeBool(PlaybackSettingsKeys.AutoSkipCredits, value)
Expand Down Expand Up @@ -677,6 +683,9 @@ class AndroidPlayerSettingsStore(
override suspend fun setNextUpPromptSeconds(value: Int) =
writeInt(PlaybackSettingsKeys.NextUpPromptSeconds, value.coerceIn(0, 120))

override suspend fun setNextUpEnabled(value: Boolean) =
writeBool(PlaybackSettingsKeys.NextUpEnabled, value)

override suspend fun setResumeRewindSeconds(value: Int) =
writeIntLocal(PlaybackSettingsKeys.ResumeRewindSeconds, value.coerceIn(0, 30))

Expand Down Expand Up @@ -1130,7 +1139,21 @@ class AndroidPlayerSettingsStore(
// from the response is one this server's contract does not
// know (older revision); the local value is kept rather than
// guessed at.
val entry = effective[key] ?: continue
val entry = effective[key]
if (entry == null) {
// A server whose manifest lacks a manifest-detected key
// holds no row for this device, so the marker a local
// write left (Show Next Up's time choice writes
// next_up_enabled too) would pin its picker to this
// device. The unconfirmed mark stays, so the write is
// still sent once the server stores the key.
if (key in PlaybackSettingsKeys.ManifestDetectedKeys &&
contractRevision?.stores(scope.serverUrl, key) == false
) {
overrides -= key
}
continue
}
if (key in unconfirmed) {
if (entry.scope == SettingScope.PROFILE_DEVICE.wire) {
unconfirmed -= key
Expand Down Expand Up @@ -1240,6 +1263,7 @@ class AndroidPlayerSettingsStore(
store.edit {
it[booleanPreferencesKey(scope.keyPrefix + key)] = value
markDeviceOverride(it, scope, key)
markUnconfirmedIfManifestDetected(it, scope, key)
}
serverSettingsFlusher.enqueue(scope.profileId, key, value.toString(), scope.serverUrl, scope.authority)
}
Expand Down Expand Up @@ -1284,6 +1308,7 @@ class AndroidPlayerSettingsStore(
store.edit {
it[stringPreferencesKey(scope.keyPrefix + key)] = value
markDeviceOverride(it, scope, key)
markUnconfirmedIfManifestDetected(it, scope, key)
}
serverSettingsFlusher.enqueue(scope.profileId, key, value, scope.serverUrl, scope.authority)
}
Expand Down Expand Up @@ -1330,6 +1355,22 @@ class AndroidPlayerSettingsStore(
private fun deviceOverridesKey(scope: Scope): Preferences.Key<Set<String>> =
stringSetPreferencesKey(scope.keyPrefix + DEVICE_OVERRIDE_KEYS)

/**
* A key the server may not store yet ([PlaybackSettingsKeys.ManifestDetectedKeys])
* stays unconfirmed, like the cellular pair, so a write the flusher held while
* the manifest was unknown is sent again by the first refresh rather than
* replaced with the server's default.
*/
private fun markUnconfirmedIfManifestDetected(
prefs: androidx.datastore.preferences.core.MutablePreferences,
scope: Scope,
key: String,
) {
if (key in PlaybackSettingsKeys.ManifestDetectedKeys) {
prefs[unconfirmedKeysKey(scope)] = prefs[unconfirmedKeysKey(scope)].orEmpty() + key
}
}

private fun unconfirmedKeysKey(scope: Scope): Preferences.Key<Set<String>> =
stringSetPreferencesKey(scope.keyPrefix + UNCONFIRMED_GATED_KEYS)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.siloserver.silo.common.settings

import androidx.compose.runtime.Composable
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import org.siloserver.silo.common.R

/**
* The Show Next Up picker: one control over `playback.next_up_enabled` and
* `playback.next_up_prompt_seconds`. A choice is the seconds before the end
* (0 = at end), or null for Off.
*/
object NextUpChoice {
private val promptSeconds: List<Int?> = listOf(0, 10, 30, 60, 120)

/**
* Off comes first while the server stores the setting, and while this
* device's last choice is Off and the server's manifest is not read yet,
* so that choice stays visible and can be changed.
*/
fun options(offSupported: Boolean, enabled: Boolean): List<Int?> =
if (offSupported || !enabled) listOf(null) + promptSeconds else promptSeconds

fun selected(enabled: Boolean, seconds: Int): Int? = if (enabled) seconds.coerceAtLeast(0) else null

/**
* Off leaves the seconds alone. A time writes both keys, so the picker's
* choice is this device's whole choice: one inherited half would follow a
* later profile change to Off, including one the server reports only after
* its manifest is read. The flusher holds the key while the manifest is
* unknown and drops it for a server that lacks it, so that server is never
* sent it.
*/
suspend fun apply(store: PlayerSettingsStore, choice: Int?) {
if (choice == null) {
store.setNextUpEnabled(false)
return
}
store.setNextUpEnabled(true)
Comment thread
Quick104 marked this conversation as resolved.
Resolved
store.setNextUpPromptSeconds(choice)
}
}

/** The phone and TV label for a [NextUpChoice] choice. */
@Composable
fun nextUpChoiceLabel(choice: Int?): String = when {
choice == null -> stringResource(R.string.settings_off)
choice <= 0 -> stringResource(R.string.settings_nextUp_atEnd)
choice < 60 -> pluralStringResource(R.plurals.settings_nextUp_secondsBeforeEnd, choice, choice)
else -> (choice / 60).let { pluralStringResource(R.plurals.settings_nextUp_minutesBeforeEnd, it, it) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ interface PlayerSettingsStore {
val bufferingQualityModeSupportedFlow: Flow<Boolean>
get() = flowOf(true)

/**
* `playback.next_up_enabled`: false turns Next Up off. True against a
* server whose manifest lacks the setting.
*/
val nextUpEnabledFlow: Flow<Boolean>
get() = flowOf(true)

/**
* True once the active server's manifest is known to define
* `playback.next_up_enabled`: the Show Next Up picker offers Off only then.
*/
val nextUpEnabledSupportedFlow: Flow<Boolean>
get() = flowOf(true)

// Booleans
/**
* The deprecated boolean, projected from [introSkipModeFlow] rather than
Expand Down Expand Up @@ -228,6 +242,9 @@ interface PlayerSettingsStore {
suspend fun setAudioSyncMs(value: Int)
suspend fun setSubtitleSyncMs(value: Int)
suspend fun setNextUpPromptSeconds(value: Int)

/** Writes `playback.next_up_enabled`; offered only while [nextUpEnabledSupportedFlow]. */
suspend fun setNextUpEnabled(value: Boolean) = Unit
suspend fun setSleepTimerDefaultMinutes(value: Int)
/** Set resume skip-back seconds (clamped 0..30; 0 = off). */
suspend fun setResumeRewindSeconds(value: Int)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,45 @@ class AndroidPlayerSettingsStoreTest {
assertTrue(store.bufferingQualityModeSupportedFlow.first())
}

@Test
fun `Next Up stays on against a server whose manifest lacks the Off setting`() = runTest {
var keys: Set<String> = setOf(PlaybackSettingsKeys.PreferredQuality)
var contract = capabilitiesAt(30)
val api = FakeSettingsApi(
effective = mapOf(stored(PlaybackSettingsKeys.NextUpEnabled, JsonPrimitive(false))),
)
val store = AndroidPlayerSettingsStore(
context = mockContextStub(),
legacyCache = fakeLegacyCache,
getActiveProfileId = { activeProfileId },
getServerUrl = { serverUrl },
serverSettingsFlusher = fakeFlusher,
settingsRepository = SettingsRepository(api),
getDeviceId = { null },
contractRevision = SettingsContractRevision({ contract }, { serverUrl }, { ApiResult.Success(keys) }),
dataStoreFactory = { _, id ->
PreferenceDataStoreFactory.create(produceFile = { File(tempFolder.root, "ds_nu_$id.preferences_pb") })
},
)
store.setNextUpEnabled(false)
assertFalse(store.nextUpEnabledFlow.first(), "the last choice seen, until the manifest is read")

// A server without the setting: Off hides and Next Up shows as before.
store.refreshFromServer()
assertFalse(PlaybackSettingsKeys.NextUpEnabled in api.requestedKeys)
assertFalse(store.nextUpEnabledSupportedFlow.first())
assertTrue(store.nextUpEnabledFlow.first())
// That server holds no device row for it, so the picker isn't pinned to this device.
assertFalse(PlaybackSettingsKeys.NextUpEnabled in store.deviceOverrideKeysFlow.first())

// The server upgrades to a contract with the setting.
keys = keys + PlaybackSettingsKeys.NextUpEnabled
contract = capabilitiesAt(31)
store.refreshFromServer()
assertTrue(store.nextUpEnabledSupportedFlow.first())
assertFalse(store.nextUpEnabledFlow.first())
}

@Test
fun `cellular quality is left out of the batch while the server revision is unknown`() = runTest {
val contractRevision = SettingsContractRevision(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.siloserver.silo.common.settings

import java.lang.reflect.Proxy
import kotlinx.coroutines.test.runTest
import kotlin.test.Test
import kotlin.test.assertEquals

class NextUpChoiceTest {
@Test
fun offIsOfferedWhereTheServerStoresItAndWhileASavedOffAwaitsTheManifest() {
val times = listOf(0, 10, 30, 60, 120)
assertEquals(listOf<Int?>(null) + times, NextUpChoice.options(offSupported = true, enabled = true))
assertEquals(times, NextUpChoice.options(offSupported = false, enabled = true))
// A saved Off before the manifest is read stays visible and selected.
assertEquals(listOf<Int?>(null) + times, NextUpChoice.options(offSupported = false, enabled = false))
assertEquals(null, NextUpChoice.selected(enabled = false, seconds = 30))
}

@Test
fun aTimeIsAChoiceOfBothKeys() = runTest {
// On already (inherited from the profile, or not yet known from the
// manifest): the time still writes On, so this device's choice survives
// the profile turning Next Up off later.
assertEquals(listOf("enabled=true", "seconds=10"), writes(10))
assertEquals(listOf("enabled=true", "seconds=0"), writes(0))
assertEquals(listOf("enabled=false"), writes(null))
}

private suspend fun writes(choice: Int?): List<String> {
val calls = mutableListOf<String>()
val unused = Proxy.newProxyInstance(
PlayerSettingsStore::class.java.classLoader,
arrayOf(PlayerSettingsStore::class.java),
) { _, method, _ -> throw UnsupportedOperationException(method.name) } as PlayerSettingsStore
val store = object : PlayerSettingsStore by unused {
override suspend fun setNextUpEnabled(value: Boolean) { calls += "enabled=$value" }
override suspend fun setNextUpPromptSeconds(value: Int) { calls += "seconds=$value" }
}
NextUpChoice.apply(store, choice)
return calls
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,30 @@ fun PlayerScreen(
// resolves when the service binds. We hold the controller in a compose
// state so downstream effects can re-run once it's ready.
var mediaController by remember { mutableStateOf<MediaController?>(null) }
// With Next Up off, the end of playback leaves the player like Back. The
// position ticker stops in the background, so report the end position
// first; the exit saves the last reported one. In picture-in-picture,
// leaving the route would fill the window with the screen behind the
// player, so the ended frame stays until picture-in-picture ends. Playback
// restarted from its controls meanwhile (playing or paused partway) keeps
// the player; its next end asks again.
LaunchedEffect(Unit) {
viewModel.closeAtEndRequests.collect {
mediaController?.takeIf { it.mediaItemCount > 0 }?.let { controller ->
viewModel.onPositionChanged(controller.currentPosition, controller.duration)
}
if (pictureInPictureCoordinator.isInPictureInPictureMode.value) {
pictureInPictureCoordinator.isInPictureInPictureMode.first { !it }
val controller = mediaController
if (controller != null && controller.mediaItemCount > 0 &&
(controller.playbackState == Player.STATE_READY || controller.playbackState == Player.STATE_BUFFERING)
) {
return@collect
}
}
exitPlayer()
Comment thread
Quick104 marked this conversation as resolved.
Resolved
}
}
val playWhenReadyReconciliationGate = remember(mediaController, roomId) {
PlayWhenReadyReconciliationGate()
}
Expand Down Expand Up @@ -1336,6 +1360,9 @@ fun PlayerScreen(

override fun onPlaybackStateChanged(playbackState: Int) {
viewModel.onBufferingChanged(playbackState == Player.STATE_BUFFERING)
if (playbackState == Player.STATE_BUFFERING || playbackState == Player.STATE_READY) {
viewModel.onPlaybackLeftEnd()
}
if (watchParty != null) sampleRoomEngine(controller)
if (playbackState == Player.STATE_ENDED) {
viewModel.onPlayingChanged(false)
Expand Down
Loading
Loading