Skip to content

feat(themes): play local theme music on detail pages - #678

Merged
Quick104 merged 3 commits into
Silo-Server:mainfrom
Rhainland:feat/theme-music
Oct 24, 2026
Merged

Quick104 merged 3 commits into
Silo-Server:mainfrom
Rhainland:feat/theme-music

Conversation

@Rhainland

@Rhainland Rhainland commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #376
Related issue: Silo-Server/silo-server#937
Validation tasks: none

The server finds local theme songs (theme.mp3 and 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

  • Item detail now reads themes from 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.
  • One app-wide player, ported from the web app's ThemeMusic, 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, when the app goes to the background (after a 2-second grace period) and as soon as playback starts. It continues onto a next page with the same theme, such as a season that inherits its series' set. It never starts over other audio and stops on audio-focus loss. On series pages, the selected episode (phone) or hero episode (TV) plays the set it resolves to, so a season or episode opened on its series page plays its own theme.
  • ui.theme_music_enabled and ui.theme_music_loop are 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.
  • Re-vendors the API v2 fixtures to add the item detail and theme bodies; existing fixtures are unchanged.

Surfaces: phone app, TV app and the shared code. No server change is needed.

Validation

  • Unit tests: shared 2101 passed; android-shared 1850 passed; TV 1323 passed; phone 906 of 907 passed. The failure, ReflowStyleTest > line height flows from settings, also fails on the base commit and is unrelated.
  • New tests cover the theme fixtures, the grant and capability API, the player (fades, loop, converted replay, retry, suspend and resume, focus loss), the page coordinator (setting and capability gating, grace period, continuity, other audio, playback interrupt) and the two settings.
  • Both debug APKs build.
  • Emulators against a current server with MP3, Opus, ALAC and FLAC themes: each theme played as music with audio focus; the ALAC theme arrived converted to AAC; leaving a page, starting playback and returning behaved as described above; a looping theme fetched a new grant when the old one expired; a loop value set for the profile on another device reached the app; the TV kept its own device value.

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

  • Off by default. A server older than settings revision 11 or without the theme capability plays nothing.
  • The server's settings manifest still lists both keys for the web only; it should add android and android_tv.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code (in T3 Code)
  • Tool(s): Claude Code; Codex CLI for one of the two reviewers
  • Model(s): claude-opus-5-5; gpt-6.1-sol
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: four rounds of independent review by claude-opus-5-5 and gpt-6.1-sol over correctness, standards and the issue's requirements. Fixed: the outgoing theme blocking the next one, resuming over newly started music, playback start only pausing the theme, the capability answer never refreshing, season and episode themes on the phone series page, and a season switch briefly playing the series theme. Dismissed with reasons: a claim that loading pages stop the theme (they never pass an empty selection), duplicated phone and TV settings UI (per-platform UI is the repo's pattern), and a failed episode-detail read keeping the previous season's theme (needs a partial network failure).

Note

Add theme music playback on Android and TV detail pages

  • Adds a theme-music stack: ThemeMusicCoordinator and ThemeMusicPlayer in 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.
  • Adds the V2 API client ThemeMusicV2Api for theme capability and playback grants, plus ItemDetail theme fields in the catalog and API models. Grant URLs are excluded from string output.
  • Android and TV detail pages now play their selected theme while visible via DetailThemeMusic and ThemeMusicService (ExoPlayer-backed, with device codec probing for accepted formats). Series and season pages prefer the next-up episode's themes.
  • Adds Theme Music and Loop toggles to both platform settings screens, backed by new per-profile settings keys gated to server contract revision 11. Both default to false.
  • Behavioral Change: theme-music settings keys are omitted when syncing from servers below revision 11; SettingsContractRevision.stores now uses DeviceSettingRevisions.minimumRevision instead of the cellular-quality lookup for non-manifest settings.

Macroscope summarized 4582309.

@silo-triage silo-triage Bot added the size/XXL 1000–2999 added + deleted lines (all files); change volume, not priority. label Oct 23, 2026
@silo-kody

silo-kody Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 595aa781-3c4d-4876-8193-f977cfa1e459
📥 Commits

Reviewing files that changed from the base of the PR and between 5e19a58 and 35758d4.

📒 Files selected for processing: 37
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/di/PlayerInfraModule.kt
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/settings/AndroidPlayerSettingsStore.kt
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/settings/PlayerSettingsStore.kt
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/settings/ServerSettingsFlusher.kt
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/thememusic/DetailThemeMusic.kt
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/thememusic/ThemeMusicService.kt
  • android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/settings/AndroidPlayerSettingsStoreTest.kt
  • android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/settings/ServerDrivenConfigRefresherTest.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/detail/ItemDetailScreen.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/settings/PlaybackSettings.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/settings/SettingsPages.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/settings/ThemeMusicSettings.kt
  • androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/ui/screens/player/PlayerViewModelLoadOwnershipIntegrationTest.kt
  • androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/detail/TvItemDetailScreen.kt
  • androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/settings/TvSettingsScreen.kt
  • androidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/testing/FakePlayerSettingsStore.kt
  • scripts/sync-apiv2-fixtures.sh
  • shared/src/commonMain/kotlin/org/siloserver/silo/di/NetworkModule.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/model/catalog/CatalogModels.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/model/settings/DeviceSettingRevisions.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/model/settings/PlaybackSettingsKeys.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/network/apiv2/CatalogDetailReadV2Models.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/network/apiv2/ThemeMusicV2Api.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/playback/theme/ThemeMusicCoordinator.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/playback/theme/ThemeMusicPlayer.kt
  • shared/src/commonTest/kotlin/org/siloserver/silo/network/apiv2/ApiV2ContractTest.kt
  • shared/src/commonTest/kotlin/org/siloserver/silo/network/apiv2/ThemeMusicContractTest.kt
  • shared/src/commonTest/kotlin/org/siloserver/silo/network/apiv2/ThemeMusicV2ApiTest.kt
  • shared/src/commonTest/kotlin/org/siloserver/silo/playback/theme/ThemeMusicCoordinatorTest.kt
  • shared/src/commonTest/kotlin/org/siloserver/silo/playback/theme/ThemeMusicPlayerTest.kt
  • shared/src/commonTest/resources/api/v2/fixtures/SOURCE
  • shared/src/commonTest/resources/api/v2/fixtures/get_catalog_item_ok.json
  • shared/src/commonTest/resources/api/v2/fixtures/index.json
  • shared/src/commonTest/resources/api/v2/fixtures/theme_songs_capability.json
  • shared/src/commonTest/resources/api/v2/fixtures/theme_songs_playback.json
  • shared/src/commonTest/resources/api/v2/fixtures/theme_songs_playback_converted.json
  • shared/src/commonTest/resources/api/v2/fixtures/theme_songs_playback_not_acceptable.json

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

This change adds local theme music to Android and Android TV detail pages. It adds catalog theme data, API v2 capability and playback-grant support, shared playback coordination, revision-gated settings, and platform audio integration.

Changes: Theme music playback

Layer / File(s) Summary
Theme metadata and API contract
shared/src/commonMain/kotlin/org/siloserver/silo/model/catalog/CatalogModels.kt, shared/src/commonMain/kotlin/org/siloserver/silo/network/apiv2/*, shared/src/commonTest/kotlin/org/siloserver/silo/network/apiv2/*, shared/src/commonTest/resources/api/v2/fixtures/*, scripts/sync-apiv2-fixtures.sh, shared/src/commonMain/kotlin/org/siloserver/silo/di/NetworkModule.kt
Catalog details can carry theme selections. The API client requests capabilities and playback grants, resolves relative grant URLs, and identifies converted grants. Fixtures and tests cover catalog themes, capabilities, original and converted playback, and HTTP 406 responses.
Revision-gated preferences and settings controls
shared/src/commonMain/kotlin/org/siloserver/silo/model/settings/*, android-shared/src/androidMain/kotlin/org/siloserver/silo/common/settings/*, android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/settings/*, androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/settings/*, androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/ui/screens/player/PlayerViewModelLoadOwnershipIntegrationTest.kt, androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/settings/TvSettingsScreen.kt, androidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/testing/FakePlayerSettingsStore.kt
Theme music and loop settings are added with revision 11 requirements and false defaults. Android and TV settings screens provide switches and device-override reset actions. Tests cover setting writes, revision-gated refresh, and updated test stores.
Shared playback and coordination
shared/src/commonMain/kotlin/org/siloserver/silo/playback/theme/*, shared/src/commonTest/kotlin/org/siloserver/silo/playback/theme/*
The shared player manages grants, fades, looping, retries, suspension, and interruptions. The coordinator gates playback and manages page changes, capability caching, and delayed release. Tests cover player and coordinator behavior.
Android audio service and dependency wiring
android-shared/src/androidMain/kotlin/org/siloserver/silo/common/di/PlayerInfraModule.kt, android-shared/src/androidMain/kotlin/org/siloserver/silo/common/thememusic/ThemeMusicService.kt
The service connects settings, identity changes, playback starts, API requests, and ExoPlayer audio to the shared playback components. It probes supported audio formats and configures load-error retries.
Lifecycle-aware detail-page integration
android-shared/src/androidMain/kotlin/org/siloserver/silo/common/thememusic/DetailThemeMusic.kt, androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/detail/ItemDetailScreen.kt, androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/detail/TvItemDetailScreen.kt
Active detail pages show their theme selection, and inactive or disposed pages hide it. Android detail pages retain the last selection while episode data loads; TV pages use the current detail themes.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant DetailPage
  participant DetailThemeMusic
  participant ThemeMusicService
  participant ThemeMusicCoordinator
  participant ThemeMusicPlayer
  participant ThemeMusicV2Api
  participant ThemeAudio
  DetailPage->>DetailThemeMusic: provide current theme selection
  DetailThemeMusic->>ThemeMusicService: show active page
  ThemeMusicService->>ThemeMusicCoordinator: show page and selection
  ThemeMusicCoordinator->>ThemeMusicPlayer: select theme
  ThemeMusicPlayer->>ThemeMusicService: request playback grant
  ThemeMusicService->>ThemeMusicV2Api: request profile playback grant
  ThemeMusicV2Api-->>ThemeMusicService: return grant
  ThemeMusicPlayer->>ThemeAudio: create and play audio
Loading

Suggested reviewers: quick104

Merge Risk: 🔵 Low · up to 35758

Theme music can briefly interfere with other audio when playback starts or stops. The affected windows are narrow and the feature defaults off, so the change is mergeable with owner awareness and follow-up.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 13.84% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 159 functions across 30 files. (7 skipped… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title "feat(themes): play local theme music on detail pages" matches the main change. The PR adds theme-music playback on movie, show, season, and episode detail pages in the Android phone and TV …
Linked Issues check Passed Directly linked issue #376 is the only active target. Its coding requirements map to the PR as follows.

- v2 fixtures: The PR adds get_catalog_item_ok.json, three theme-song fixtures (capability, p…
Out of Scope Changes check Passed Every changed area supports an objective of #376.

- DeviceSettingRevisions replaces CellularQuality in AndroidPlayerSettingsStore and ServerSettingsFlusher. It adds the revision-11 minimum fo…
Description check Passed The pull request description clearly explains the theme music feature, affected Android phone and TV surfaces, API and settings changes, validation, evidence, and risks. It directly matches the change…
Full details: Title check

Explanation

The title "feat(themes): play local theme music on detail pages" matches the main change. The PR adds theme-music playback on movie, show, season, and episode detail pages in the Android phone and TV apps, behind an opt-in setting. The title is specific, concise, and follows a conventional commit style.

Full details: Linked Issues check

Explanation

Directly linked issue #376 is the only active target. Its coding requirements map to the PR as follows.

  • v2 fixtures: The PR adds get_catalog_item_ok.json, three theme-song fixtures (capability, playback, converted playback) and a 406 not-acceptable fixture. ApiV2ContractTest decodes them. The base commit has no theme_songs_capability.json, so these fixtures are new, not edited.
  • Item detail themes: ItemDetailReadV2 maps themes to ItemDetail.themes (ThemeSelection and ThemeTrack). ThemeMusicContractTest covers this.
  • Capability: ThemeMusicV2Api.capability() requires state == "available" and allowed != false. The coordinator plays only when the cached capability is true.
  • Playback grants: ThemeMusicV2Api.grant() sends accepted_formats from probed decoders. It resolves relative URLs and keeps proxy-origin URLs. ThemeGrant and grant toString() omit URLs. Tests cover these cases.
  • Converted streams: ThemeMusicPlayer disables seek-based looping for converted streams and requests a fresh grant to replay them.
  • Settings: ui.theme_music_enabled and ui.theme_music_loop are added to PlaybackSettingsKeys, with profile and device scope and default false. AndroidPlayerSettingsStore and PlayerSettingsStore expose flows and setters. DeviceSettingRevisions gates them at revision 11.
  • Settings UI: The phone adds a Theme Music section to Settings → Interface. TV adds a Theme Music group to Settings → General, with a "Use Profile Setting" action.
  • Playback with fades: ThemeMusicPlayer fades in and out to TARGET_VOLUME 0.35.
  • Stop triggers: The coordinator stops on page exit after a 2-second grace period, on background, on interrupt (playback start) and on identity reset (profile change). The player stops on audio-focus loss.
  • Android TV: TvItemDetailScreen calls DetailThemeMusic.

Limitation: On TV, a season or episode opened from its series page plays the series set. That page has no per-episode detail, and the PR discloses this. The issue does not require per-episode resolution on that page.

This verdict relies on the PR summary and the test list. I did not read the source files directly. The base-commit check confirmed only that the theme fixtures are new.

Full details: Out of Scope Changes check

Explanation

Every changed area supports an objective of #376.

  • DeviceSettingRevisions replaces CellularQuality in AndroidPlayerSettingsStore and ServerSettingsFlusher. It adds the revision-11 minimum for the theme keys. This is needed for the new settings.
  • ProfileLayeredSwitchRow changes from private to internal. The TV and phone settings screens reuse it for the theme toggles.
  • PlaybackSettingsKeys, CatalogModels, ItemDetailReadV2 and ThemeMusicV2Api implement the v2 contract.
  • DetailThemeMusic, ThemeMusicService, ThemeMusicCoordinator and ThemeMusicPlayer implement playback and stop behavior.
  • ItemDetailScreen and TvItemDetailScreen bind the theme to detail pages. ItemDetailScreen retains the last selection while an episode loads.
  • The fixture files, SOURCE and scripts/sync-apiv2-fixtures.sh re-vendor the v2 contract that the issue names.
  • The tests cover the new code.

The PR does not change server code. The server settings manifest is listed as a follow-up in the PR risks, not as a change in this PR. No unrelated behavior appears in the summary.

Full details: Description check

Explanation

The pull request description clearly explains the theme music feature, affected Android phone and TV surfaces, API and settings changes, validation, evidence, and risks. It directly matches the changeset and objectives.

Full details: Docstring Coverage

Explanation

Docstring coverage is 13.84% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 159 functions across 30 files. (7 skipped: 7 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@silo-triage silo-triage Bot added enhancement New feature or request priority: P2 Limited scope, workaround exists, or polish labels Oct 23, 2026
if (capabilityRead?.isActive == true) return
capabilityRead = scope.launch {
val answer = capability() ?: return@launch
available = answer

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Kody Rules critical

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

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.

​

​

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +139 to +141
val granted = grant(ownerId, themeId) ?: return@launch
if (startGeneration != generation) return@launch
clearAudio()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Bug high

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.

​

​

@Rhainland Rhainland Oct 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +119 to +127
retiring += 1
scope.launch {
try {
rampVolume(current, 0f)
} finally {
current.release()
retiring -= 1
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Bug medium

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.

​

​

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

silo-kody Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌
⚠️ 4 Kody Rule(s) were not evaluated

These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:

  • Validate download ownership before publishing subtitle bytes
  • Bind playback markers to the actual playing file
  • Share route-aware audio decisions and preserve original-format decoder fallback
  • Apply playback route eligibility consistently at admission and media loading

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.
@silo-kody

silo-kody Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

val state by viewModel.uiState.collectAsState()
org.siloserver.silo.common.thememusic.DetailThemeMusic(
org.koin.compose.koinInject(),
state.detail?.themes,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Bug medium

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.

​

​

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

silo-kody Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌
⚠️ 4 Kody Rule(s) were not evaluated

These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:

  • Validate download ownership before publishing subtitle bytes
  • Bind playback markers to the actual playing file
  • Share route-aware audio decisions and preserve original-format decoder fallback
  • Apply playback route eligibility consistently at admission and media loading

@Quick104
Quick104 merged commit 237b3f9 into Silo-Server:main Oct 24, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request priority: P2 Limited scope, workaround exists, or polish size/XXL 1000–2999 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(themes): play local theme music on detail pages

2 participants