Repository navigation
feat(themes): play local theme music on detail pages - #678
Conversation
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: 🔵 Low · up to
|
| if (capabilityRead?.isActive == true) return | ||
| capabilityRead = scope.launch { | ||
| val answer = capability() ?: return@launch | ||
| available = answer |
There was a problem hiding this comment.
Stale capability caching can update available for an inactive identity because reset() cancels the job without fencing a capability implementation that returns without observing cancellation. Add an ownership generation, increment it in reset(), capture it before starting the request, and reject obsolete results immediately after capability() returns.
Also found in:
shared/src/commonMain/kotlin/org/siloserver/silo/playback/theme/ThemeMusicCoordinator.kt:110-110shared/src/commonMain/kotlin/org/siloserver/silo/playback/theme/ThemeMusicCoordinator.kt:109-109
Kody rule violation: Revalidate asynchronous ownership before publication, launch, and cleanup
Prompt for LLM
File shared/src/commonMain/kotlin/org/siloserver/silo/playback/theme/ThemeMusicCoordinator.kt:
Line 108:
Stale capability caching can update available for an inactive identity because reset() cancels the job without fencing a capability implementation that returns without observing cancellation. Add an ownership generation, increment it in reset(), capture it before starting the request, and reject obsolete results immediately after capability() returns.
**Also found in:**
- `shared/src/commonMain/kotlin/org/siloserver/silo/playback/theme/ThemeMusicCoordinator.kt:110-110`
- `shared/src/commonMain/kotlin/org/siloserver/silo/playback/theme/ThemeMusicCoordinator.kt:109-109`
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Fixed in 2e79537. The coordinator now carries an identity counter that reset() bumps; a capability read captures it before the request and drops its answer when it changed, so a read that returns without observing cancellation can no longer publish the previous identity's answer. Covered by ThemeMusicCoordinatorTest.aCapabilityAnswerForThePreviousIdentityIsDiscarded.
There was a problem hiding this comment.
Thanks—that addresses the reported race. Checking the captured identity immediately after capability() returns prevents an obsolete result from being published even when cancellation is ignored. The regression test covers that exact scenario.
Based on your description of 2e795373f, I consider this suggestion addressed.
| val granted = grant(ownerId, themeId) ?: return@launch | ||
| if (startGeneration != generation) return@launch | ||
| clearAudio() |
There was a problem hiding this comment.
Race condition in load allows a video or another app's music to start during the asynchronous grant request after the other-audio check, then ExoThemeAudio's audio-focus request interrupts it. Revalidate playback eligibility immediately before creating and playing the granted audio.
Prompt for LLM
File shared/src/commonMain/kotlin/org/siloserver/silo/playback/theme/ThemeMusicPlayer.kt:
Line 139 to 141:
Race condition in load allows a video or another app's music to start during the asynchronous grant request after the other-audio check, then ExoThemeAudio's audio-focus request interrupts it. Revalidate playback eligibility immediately before creating and playing the granted audio.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Not changing this one. Starting video playback already ends the pending request: the session player starting calls coordinator.interrupt(), which stops immediately and bumps the player's generation, so a grant that lands afterwards is dropped before any audio is created. The remaining case, another app starting music inside the grant round trip, is a very short window, and a re-check at that point could not tell our own theme fading out from other audio, because AudioManager.isMusicActive reports both. In that case the theme would take audio focus from the other app, which the user can undo by resuming it.
There was a problem hiding this comment.
The video-playback case is covered by coordinator.interrupt() and the generation check, so that part of my suggestion was incorrect. You’re also right that an unconditional isMusicActive recheck could mistake the outgoing theme’s fade for unrelated audio.
One caveat remains: if another app starts music during the grant request, its focus request happens before the theme requests focus. The theme’s later focus request could then interrupt that app; the earlier request would not automatically pause the theme.
That leaves a narrow cross-app race, not the broader video-playback issue I reported. I wouldn’t insist on the proposed recheck as written, given its false positives. No change requested here.
| retiring += 1 | ||
| scope.launch { | ||
| try { | ||
| rampVolume(current, 0f) | ||
| } finally { | ||
| current.release() | ||
| retiring -= 1 | ||
| } | ||
| } |
There was a problem hiding this comment.
Audio lifecycle tracking in stop loses outgoing audio in an untracked fade job, so stop(immediate = true) from interrupt or reset cannot release it when video playback starts or identity switches during the 300 ms fade. Track retiring audio and its jobs so immediate stops release them as well.
Prompt for LLM
File shared/src/commonMain/kotlin/org/siloserver/silo/playback/theme/ThemeMusicPlayer.kt:
Line 119 to 127:
Audio lifecycle tracking in stop loses outgoing audio in an untracked fade job, so stop(immediate = true) from interrupt or reset cannot release it when video playback starts or identity switches during the 300 ms fade. Track retiring audio and its jobs so immediate stops release them as well.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Fixed in 2e79537. Themes fading out after a stop are now tracked as jobs, and stop(immediate = true) cancels them, which releases their audio at once; isAudible reads the same list. Covered by ThemeMusicPlayerTest.anImmediateStopAlsoReleasesAThemeStillFadingOut.
There was a problem hiding this comment.
Thanks for the fix. Tracking retiring fade jobs and canceling them on stop(immediate = true) addresses the reported lifecycle gap, while deriving isAudible from the same list keeps it consistent.
The reported regression test covers the key case: an immediate stop while a theme is still fading out. This addresses my suggestion based on your description; I haven’t independently inspected commit 2e795373f.
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Movie, show, season and episode detail pages on phone and Android TV now play the server's local theme music, as the web app does. It is opt-in: nothing plays unless "Theme Music" is on and the server reports the theme capability available. - Item detail reads `themes` from API v2; a theme plays through a short-lived grant that lists the formats this device decodes, so the server converts the rest to AAC. Signed URLs stay inside the player. - One app-wide player fades themes in and out, loops originals in place, replays converted streams with a fresh grant, and retries once. - A theme stops when its page leaves, the app goes to the background or playback starts, and continues onto a next page with the same theme (a season that inherits its series' set). It never starts over other audio and pauses on audio focus loss. - `ui.theme_music_enabled` and `ui.theme_music_loop` are device settings (contract revision 11), shown beside "Show title art" in Settings → Interface on the phone and Settings → General on TV. - Vendors the item detail and theme fixtures from silo-server. Closes Silo-Server#376
…mmediate stop A capability answer for the previous account or profile is now ignored after a reset, even when the read does not observe cancellation. An immediate stop (playback starting, a reset, the grace timeout) also releases a theme that is still fading out from an earlier stop.
2e79537 to
3df8132
Compare
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
| val state by viewModel.uiState.collectAsState() | ||
| org.siloserver.silo.common.thememusic.DetailThemeMusic( | ||
| org.koin.compose.koinInject(), | ||
| state.detail?.themes, |
There was a problem hiding this comment.
Incorrect TV theme selection uses the series detail's themes instead of the displayed episode's resolved themes in nextUpPlaybackDetail; because season and episode routes redirect to the series page, those titles play the series theme or remain silent when only the season has themes. Resolve the selection from the displayed episode's loaded detail and preserve the previous selection while that detail loads, matching the phone implementation.
Prompt for LLM
File androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/detail/TvItemDetailScreen.kt:
Line 223:
Incorrect TV theme selection uses the series detail's themes instead of the displayed episode's resolved themes in nextUpPlaybackDetail; because season and episode routes redirect to the series page, those titles play the series theme or remain silent when only the season has themes. Resolve the selection from the displayed episode's loaded detail and preserve the previous selection while that detail loads, matching the phone implementation.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Fixed in 4582309. Series and season pages on TV now play the set their hero episode resolves to (nextUpPlaybackDetail.themes: the season's, else the series'), as the phone does for its selected episode. While a new hero episode loads, the set already playing stands, so switching seasons doesn't cut out; if the load fails, the page's own set plays. Both screens also fall back to the page's set when the episode detail carries no themes.
There was a problem hiding this comment.
Thanks for the fix in 4582309e7. The behavior you describe addresses the original finding:
- TV uses the hero episode’s resolved themes, matching the phone’s selected-episode behavior.
- The current theme continues while the next episode detail loads.
- Both screens fall back to the page’s themes if the episode detail fails to load or has no themes.
Based on that description, this suggestion is addressed; I haven’t independently verified the commit.
Season and episode routes open on the series page, which played the series' set. The TV page now plays the set its hero episode resolves to (its season's, else its series'), as the phone does for its selected episode, and keeps the current set while that episode loads. Both screens fall back to the page's set when the episode detail has no themes.
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Problem
Closes #376
Related issue: Silo-Server/silo-server#937
Validation tasks: none
The server finds local theme songs (
theme.mp3and similar) and the web app plays them on title pages, but the Android phone and TV apps never did. A user reported that gap. This change plays theme music on movie, show, season and episode detail pages on both apps, behind an opt-in setting.Approach
themesfrom API v2. A theme plays through a short-lived playback grant that lists the formats this device's decoders handle, so the server converts the rest to AAC. The signed URL stays inside the theme's own player and is never logged or stored.ThemeMusic, fades themes in and out, loops originals in place, replays converted streams with a fresh grant, and retries once.ui.theme_music_enabledandui.theme_music_loopare device settings (contract revision 11), read and written like the other device playback settings, with "Use Profile Setting". They sit beside "Show title art": Settings → Interface on the phone, Settings → General on TV. Both default off, and nothing plays unless the server reports the theme capability available.Surfaces: phone app, TV app and the shared code. No server change is needed.
Validation
ReflowStyleTest > line height flows from settings, also fails on the base commit and is unrelated.Evidence
Evidence: https://evidence.siloserver.org/r/silo-android/pr-678/
Surface and build: Android phone (Pixel 7, Android 16), Android tablet (Pixel Tablet, Android 16), Android foldable (Pixel Fold, Android 16, folded and open) and Android TV (Android 14) emulators. Before is the base commit 5e19a58; after is this branch. The settings screen is the only visual change; detail pages look the same and now play audio, recorded in the evidence notes.
Risks
androidandandroid_tv.Checklist
AI Disclosure
Note
Add theme music playback on Android and TV detail pages
ThemeMusicCoordinatorandThemeMusicPlayerin shared code handle capability caching (60-second TTL), short-lived playback grants, fades, looping, suspension, and a two-second release grace period on page exit. See ThemeMusicCoordinator.kt and ThemeMusicPlayer.kt.ThemeMusicV2Apifor theme capability and playback grants, plusItemDetailtheme fields in the catalog and API models. Grant URLs are excluded from string output.DetailThemeMusicandThemeMusicService(ExoPlayer-backed, with device codec probing for accepted formats). Series and season pages prefer the next-up episode's themes.SettingsContractRevision.storesnow usesDeviceSettingRevisions.minimumRevisioninstead of the cellular-quality lookup for non-manifest settings.Macroscope summarized 4582309.