Skip to content

fix(player): choose automatic subtitles the same way on phone and TV - #572

Closed
Rhainland wants to merge 11 commits into
Silo-Server:mainfrom
Rhainland:fix/subtitle-auto-selection-parity
Closed

Rhainland wants to merge 11 commits into
Silo-Server:mainfrom
Rhainland:fix/subtitle-auto-selection-parity

Conversation

@Rhainland

@Rhainland Rhainland commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: Silo-Server/silo-server#1157
Validation tasks: unblocks #323 C2, #324 C2

Stacked on #571; review the top three commits. Merge #571 first.

The phone and TV apps choose different subtitles for the same file, and the TV app chooses the wrong one for files with more than one audio track (Silo-Server/silo-server#1157 AC2):

  • Forced ranking: with forced subtitles on, the phone lets a forced text track outrank the full-dialogue track in the preferred language. The shared resolver the TV uses never does, per the rule recorded in AutoSubtitleResolver.
  • Wrong audio: on a file whose default audio is German with English also present, the TV plays English but picks subtitles as if the audio were German, so an English-speaking profile gets full English subtitles instead of only the forced track.
  • Subtitles off: with the subtitle mode Off and "Show forced subtitles" on, both apps show nothing. The web shows the forced track in the audio language, and the apps' settings say forced subtitles cover foreign-language dialogue "even when subtitles are off".

origin/main behaves the same in all three cases.

Approach

  • The phone's automatic selection goes through the shared AutoSubtitleResolver, so phone and TV agree. A parity test compares them across modes, audio languages and the forced setting.
  • The TV fallback judges subtitles by the audio it is set to play (the planned audio track), not Media3's first track snapshot.
  • The resolver maps mode Off plus show-forced to the forced track whose language matches the audio, or nothing. An Off tapped during playback still turns subtitles fully off for that playback.

Validation

  • Unit tests on all four modules pass except ReflowStyleTest, which this change does not touch and which formats with the machine's locale. Phone and TV debug builds succeed.
  • Local server with synthetic media (German-only, partly foreign, dual-audio, MP4 text and a four-episode series): on the phone, tablet and Android TV emulators the automatic choice matched the web and the Apple apps for every fixture.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-android/pr-572/

Surface and build: Android TV and tablet emulators; this branch. Before, on main, the dual-audio file started with full English subtitles on the TV.

Risks

Viewers whose profile is set to Off now see forced subtitles for foreign-language lines when "Show forced subtitles" is on, as the setting describes and as the web already does.

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
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: an independent Claude Code review of the branch diff checked the resolver change, explicit Off handling and phone/TV parity. Its only finding in this layer, Off now showing forced subtitles, is the intended rule described above; a test pins it.

Note

Unify phone and TV automatic subtitle selection and align subtitle sync storage with the profile

  • Phone now uses the shared auto-subtitle resolver in MobileSubtitleAutoSelection.kt; the local ranking helpers (bestAutoSubtitleOrdinal, PlayerSubtitleInfo.isBitmap, etc.) are removed.
  • The shared resolveAutoSubtitle now picks a forced track matching the playing audio language even when subtitles are set to off, and language matching recognizes more ISO 639 forms in AutoSubtitleResolver.kt.
  • TV subtitle selection now uses the intended playback audio language instead of always the first mounted audio track, in TvPlayerViewModel.kt.
  • Settings contract raised to revision 18: subtitle sync can now be stored at profile scope, and the flusher in ServerSettingsFlusher.kt routes writes by profile/device scope with revision gating and stale device-row cleanup.
  • The subtitle settings UI on phone and TV adds an "Only on This Device" toggle and shows whether the subtitle delay is saved for the profile or the device.
  • Behavioral Change: editing subtitle appearance with the device override off now saves to the profile instead of implicitly enabling the device override; mobile auto-selection no longer lets a forced text track outrank a full-language track; servers below revision 18 keep subtitle sync device-scoped.

Macroscope summarized 0b78709.

Subtitle appearance and timing were always written at profile_device
scope, and every appearance edit silently turned on the device override.
A style set on the phone never reached the TV, and the settings copy
said "for this profile on this device".

Appearance edits (phone settings, the in-player style sheet, TV settings)
now save at profile scope. A device keeps its own subtitles only through
the explicit "Only on This Device" toggle, now shown on the phone too:
while it is on, appearance and timing edits go to profile_device;
turning it off deletes this device's rows. A profile save also deletes a
stale device row, so the saved value is the one on screen. Turning the
toggle on pins the appearance on screen, as on Apple.

player.subtitle_sync_ms saves at profile scope on servers at manifest
revision 18 or later and stays device-scoped below that, decided at send
time like the text-opacity gate and held while the revision is unknown.

Queued writes now carry their scope with their profile, so a profile
write is never sent as a device write or to another profile, and a
device write queued after a profile save is not deleted by it.

Includes the regenerated settings bindings (manifest revision 18).
The in-player Sync page said nothing about where the delays are kept,
and the subtitle delay is now saved for the profile on every device
while the audio delay stays on this device.

The subtitle delay now reads "Saved for this profile on all devices",
or "Only on this device" when Only on This Device is on or the server
stores timing per device only (manifest revision below 18). The audio
delay reads "PCM audio only · This device".
A profile save that also clears this device's row could fail while the
viewer turned on "Only on This Device" and set a device value. The device
write landed, then the failed profile save was queued again with its
device clear intact, and its retry deleted the newer device value.

When a failed op is queued again, a profile save now drops its device
clear if a device write for the same profile and key was handled after it
failed, or is still queued. The profile value is still retried. This is
the rule the queue already applied to a profile save that had not been
sent yet.
@silo-kody

silo-kody Bot commented Oct 14, 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 14, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2befd73e-4f49-4b17-b4cb-a7a861428ae1
📥 Commits

Reviewing files that changed from the base of the PR and between fd095bf and 0b78709.

📒 Files selected for processing: 5
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/settings/ServerSettingsFlusher.kt
  • android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/settings/ServerSettingsFlusherTest.kt
  • androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/ui/screens/player/MobileSubtitleAutoSelectionTest.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/model/playback/AutoSubtitleResolver.kt
  • shared/src/commonTest/kotlin/org/siloserver/silo/model/playback/AutoSubtitleResolverTest.kt

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b98a704c-5c7d-4e02-896c-d4ed5b21643f
📥 Commits

Reviewing files that changed from the base of the PR and between a36f4af and fd095bf.

📒 Files selected for processing: 25
  • 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/androidUnitTest/kotlin/org/siloserver/silo/common/settings/AndroidPlayerSettingsStoreTest.kt
  • android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/settings/ServerSettingsFlusherTest.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/player/MobileSubtitleAutoSelection.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/player/PlayerOverlay.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/player/PlayerSettingsSheet.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/player/PlayerViewModel.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/SettingsViewModel.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/settings/SubtitleSettings.kt
  • androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/ui/screens/player/MobileSubtitleAutoSelectionTest.kt
  • androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/player/TvPlayerViewModel.kt
  • androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/settings/TvSettingsScreen.kt
  • androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/settings/TvSettingsViewModel.kt
  • androidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/screens/player/TvAutoSubtitleFallbackTest.kt
  • shared/src/androidUnitTest/kotlin/org/siloserver/silo/model/settings/PlaybackSettingsKeysContractTest.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/model/playback/AutoSubtitleResolver.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/model/settings/PlaybackSettingsKeys.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/model/settings/SettingKeys.kt
  • shared/src/commonTest/kotlin/org/siloserver/silo/model/playback/AutoSubtitleResolverTest.kt
  • shared/src/commonTest/resources/settings/v1/SOURCE
  • shared/src/commonTest/resources/settings/v1/conformance.json
  • shared/src/commonTest/resources/settings/v1/manifest.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

Subtitle timing and appearance now support profile or device-specific saving, subject to server revision support. Mobile and TV subtitle selection also use updated shared resolution behavior.

Changes: Subtitle setting scopes

Layer / File(s) Summary
Profile scope contract
shared/src/commonMain/kotlin/org/siloserver/silo/model/settings/*, shared/src/commonTest/resources/settings/v1/*, shared/src/androidUnitTest/kotlin/org/siloserver/silo/model/settings/*
Manifest revision 18 adds profile scope for subtitle timing. Device values take precedence over profile values, and the contract fixtures include cross-device resolution cases.
Scoped writes and retries
android-shared/src/androidMain/kotlin/org/siloserver/silo/common/settings/ServerSettingsFlusher.kt, android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/settings/ServerSettingsFlusherTest.kt
The flusher queues profile and device operations separately, applies revision gates, and retries profile writes and device-row deletes independently. Tests cover coalescing, superseding writes, and retry behavior.
Subtitle scope state and writes
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/androidUnitTest/kotlin/org/siloserver/silo/common/settings/AndroidPlayerSettingsStoreTest.kt
The store chooses timing and appearance scopes, exposes whether timing is saved to the profile, and conditionally clears device timing when device-only mode is disabled. Tests cover revision and toggle behavior.
Settings controls and save-scope labels
androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/settings/*, androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/player/*, androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/settings/*
Android and TV settings expose the “Only on This Device” control and show the selected appearance scope. The player delay screen labels subtitle delay according to its save scope.

Automatic subtitle selection

Layer / File(s) Summary
Shared resolver behavior
shared/src/commonMain/kotlin/org/siloserver/silo/model/playback/AutoSubtitleResolver.kt, shared/src/commonTest/kotlin/org/siloserver/silo/model/playback/AutoSubtitleResolverTest.kt
When subtitle mode is off, the resolver can select a forced track matching the audio language if forced subtitles are enabled. Tests cover matching and disabling cases.
Mobile and TV integration
androidApp/src/androidMain/kotlin/org/siloserver/silo/android/ui/screens/player/MobileSubtitleAutoSelection.kt, androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/ui/screens/player/MobileSubtitleAutoSelectionTest.kt, androidTvApp/src/androidMain/kotlin/org/siloserver/silo/tv/ui/screens/player/TvPlayerViewModel.kt, androidTvApp/src/androidUnitTest/kotlin/org/siloserver/silo/tv/ui/screens/player/TvAutoSubtitleFallbackTest.kt
Mobile selection delegates to the shared resolver. TV selection uses the intended audio language when available and otherwise uses the mounted audio selection.

Priority: ➖ Normal

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

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant PlayerSettingsStore
  participant ServerSettingsFlusher
  participant SettingsServer
  PlayerSettingsStore->>ServerSettingsFlusher: Enqueue profile write with minimum revision
  ServerSettingsFlusher->>SettingsServer: Check manifest revision
  SettingsServer-->>ServerSettingsFlusher: Return revision
  ServerSettingsFlusher->>SettingsServer: Write profile value when supported
  ServerSettingsFlusher->>SettingsServer: Delete device row when requested
Loading

Suggested reviewers: quick104

Merge Risk: ⚪ Minimal · up to fd095

Subtitle timing and appearance can now be saved per profile or per device, and automatic subtitle selection follows the same rules on phone and TV. No concrete blocking defect remains. The main behavior change to be aware of is that profiles with subtitles set to Off may now show forced subtitles for foreign-language dialogue when "Show forced subtitles" is enabled.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 26.73% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 101 functions across 22 files. (3 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 clearly and concisely describes the main change: aligning automatic subtitle selection between phone and TV.
Description check Passed The description directly explains the subtitle-selection differences, implementation approach, validation, risks, and related issue.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 26.73% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 101 functions across 22 files. (3 skipped: 3 unsupported.)

✨ 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.

… would drop

Turning "Only on This Device" off while the server revision was unknown
(offline) skipped the subtitle timing clear for good, so the device delay
kept overriding the profile's. The clear is now queued gated on revision
18 and held until the revision is known; below 18 it is dropped, as the
device row is the only timing there. It is decided in the toggle's edit
transaction, so a timing edit made after it is never cleared.

A second profile edit inside the debounce, or made while the first one
waited to retry, replaced the first one's device clear with false, and
the stale device row kept outranking the saved value. The clear now
carries over unless a device write came in between.

A failed device clear after a landed profile PUT retried the PUT too,
which could put this value back over a newer one saved elsewhere. Only
the clear is retried now.

A timing save queued before the revision was known that fell back to
the device row (revision 17) and failed was retried over a newer device
write made after the revision was learned. It is now dropped when a
newer device write supersedes it.
The phone kept its own copy of subtitle auto-selection, which let a forced
text track outrank the full-dialogue track whenever "Show forced
subtitles" was on. The shared resolver the TV player and the TV detail
page use records the product decision (2026-08-16) that forced never
outranks full dialogue when subtitles are wanted, so the two apps started
the same file on different tracks.

The phone now hands its rows to the shared resolveAutoSubtitle, keeping
only its own hearing-impaired reading of the runtime label, source and
URL. A parity test checks the phone and the shared resolver land on the
same row across modes, audio languages and the forced toggle.
On a file whose default audio track is not the profile's language, TV
playback started with full subtitles where only the forced track
belonged. Dual Audio (German default, English chosen for the profile)
played English audio with "English SRT" on, while web and phone showed
only "English Forced".

The TV fallback ranked subtitles against the audio Media3 reported as
selected in its first track snapshot. That is still the file's default
(German) until the planned English track is switched in, so English audio
looked foreign. The fallback now uses the audio this playback is set to
play (the planned or chosen catalog track), and reads the mounted
selection only when that is unknown, as the phone already does.
With subtitles set to Off (for a series or the profile) and "Show forced
subtitles" on, the phone started the next episode with nothing on screen,
while web and TV showed the forced line for the foreign-language
dialogue. The TV settings copy and Apple both promise forced subtitles
"even when subtitles are off".

The shared resolver turned mode "off" straight into Disable, and the
phone's automatic start applied that over the forced track the plan had
chosen. Mode "off" now selects the forced track in the language of the
audio that will play when forced subtitles are on, and nothing when there
is none (web parity). The phone, the TV fallback and the TV detail
preview all use this rule. Turning subtitles Off during playback is still
fully off for that playback, since that path does not go through the
resolver.
@Rhainland
Rhainland force-pushed the fix/subtitle-auto-selection-parity branch from f48a488 to fd095bf Compare October 14, 2026 11:04
@silo-kody

silo-kody Bot commented Oct 14, 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 ❌

…retries per write

A subtitle timing clear gated on revision 18 took the slot of an unsent
device write. Below 18 the clear is dropped, so the edit was lost and the
next refresh put the old server value back. The clear now keeps the write
it replaced and sends it when the server turns out to be below 18.

Failures and device writes in one drain were ordered per pass, so a
device write later in the same snapshot looked no newer than a failed
profile save before it. Its retry could then delete or overwrite that
newer device value. They are now ordered per write.
…during it

When a profile save had landed and the follow-up device clear threw (a
cancelled flush), the whole save was requeued. Its retry replayed the
profile value and could overwrite a newer one saved from another device.
Only the clear is retried now.
@silo-triage silo-triage Bot added the size/XXL 1000–2999 added + deleted lines (all files); change volume, not priority. label Oct 16, 2026
@silo-kody

silo-kody Bot commented Oct 16, 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 ❌

A revision-gated profile save held while the revision is unknown is now
marked when this device writes its own value after it, and dropped if it
then resolves to the device row. A failed device write kept by a
revision-gated clear now retries inside that clear, so the retry checks
the revision again.

(cherry picked from commit 37914e5)
The shared Auto resolver folded only seven ISO 639-2 codes, so after the
phone moved onto it a preference of "it" no longer matched an "ita"
track. It now uses the full table the phone used before.

(cherry picked from commit 1a9d5b2032c3f03ec0e604c188b6143a31a146a4)
@silo-kody

silo-kody Bot commented Oct 17, 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 ❌

@Quick104

Copy link
Copy Markdown
Contributor

This PR is superseded: #680 (33bc57d on main) took it over, keeping its commits and authorship, and merged on October 25. On main, the phone's Auto goes through the shared resolveAutoSubtitle, the TV picks subtitles by the audio it plans to play, and Off plus "Show forced subtitles" shows the forced track in the audio's language. Since main covers everything this branch changes, I recommend closing it.

Closing it closes no issues. Silo-Server/silo-server#1157 stays open for the other clients.

Thank you for the work, @Rhainland.

Posted by Claude Code (claude-opus-5-5) for a maintainer.

@Quick104 Quick104 closed this Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working impact: playback Can't play, stalls, or wrong media priority: P2 Limited scope, workaround exists, or polish size/XXL 1000–2999 added + deleted lines (all files); change volume, not priority. stacked Stacked on another open PR or branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants