Repository navigation
feat(player): let viewers turn Next Up off #995
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
base: main
Are you sure you want to change the base?
Changes from 40 commits
6ad4de4
445ca87
9a0ef16
fa22e02
4c481a2
c693acd
85cf2c3
f6fdb38
de577ed
966f8d8
635f5ec
3927ac8
b48f48b
41e4931
31647af
33ac5cb
67d1743
3bea593
7b762e7
bb46caf
9f9d2ae
0e2a454
53b6474
ed16560
b18ad7a
72ea43f
a255ed4
5423f7c
d4af5a9
7f35d33
e44df67
6757e2b
38a1f21
01aca70
ea74cc4
b1a8258
af19cc3
b2340c3
4b72528
a8fae39
5982241
bfc6ff8
be56968
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) | ||
| 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 |
|---|---|---|
| @@ -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 |
|---|---|---|
|
|
@@ -712,6 +712,32 @@ 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. The check runs outside | ||
| // picture-in-picture too, so a second end queued while the window was up | ||
| // can't close playback restarted since. | ||
| 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() | ||
|
Quick104 marked this conversation as resolved.
Resolved
Quick104 marked this conversation as resolved.
Resolved
Comment on lines
+733
to
+738
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A seek during deferred end closure can be lost. When Off closes playback at the end in picture-in-picture, a seek that needs a server re-anchor can start before the window closes. The mounted media stays in Check for a pending seek or re-anchor before closing the player. Wait for it to settle. After a rollback, close as before. After a replacement mounts, keep playback. Close immediately when no seek is pending. Relevant code:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confirmed as a narrow case, and left for the maintainers. Off closes at the end while the phone is in picture-in-picture, so the close waits for the window to end. If a seek that needs a server re-anchor starts from the system controls during that wait, and the window ends before the seek settles, the guard still sees 🤖 Claude Code (claude-opus-5-5) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Quick104 Thanks for confirming. I won’t mark the finding as addressed. Learnings added
You are interacting with an AI system. |
||
| } | ||
| } | ||
| val playWhenReadyReconciliationGate = remember(mediaController, roomId) { | ||
| PlayWhenReadyReconciliationGate() | ||
| } | ||
|
|
@@ -1433,6 +1459,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) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.