Skip to content

feat: Add dual subtitle playback with translation support.#5839

Open
whyzgeek wants to merge 1 commit into
yuliskov:masterfrom
whyzgeek:dual_subtitles
Open

feat: Add dual subtitle playback with translation support.#5839
whyzgeek wants to merge 1 commit into
yuliskov:masterfrom
whyzgeek:dual_subtitles

Conversation

@whyzgeek

@whyzgeek whyzgeek commented May 30, 2026

Copy link
Copy Markdown

Dual subtitles with on-the-fly translation

Adds a "dual subtitles" mode that renders a second translated line below the
primary subtitle while a video plays. This is very useful for language learners. The translation source is picked
automatically:

  1. YouTube's official tlang timedtext when the selected caption track is
    marked translatable — same XML the YouTube site uses, no extra latency, and
    line breaks stay aligned with the primary track.
  2. Google Translate web endpoint as a per-line fallback for tracks that
    can't be translated by YouTube (e.g. user-uploaded SRT-style captions),
    with an LRU cache of the last 200 lines.
    The translated line is rendered in italic light-green directly under the
    original by a small extension to the SmartTube ExoPlayer fork's
    SubtitlePainter, so both lines paint as a single block (no flicker, no
    parallel SubtitleView overlays).

Why a Painter-level change

The translated text is merged into the same Cue as the original, then tagged
with an android.text.Annotation span (smarttube-dual / translation).
SubtitlePainter detects the span and renders the second line with a separate
TextPaint, so the merge:

  • doesn't fight applyEmbeddedStyles (the user's caption-style prefs still
    apply to the primary line),
  • preserves cue background colors on both lines,
  • keeps a single positioning origin (no second view to keep in sync with
    player resize, AFR switching, PiP, etc.).

User-facing controls

  • Subtitles → Dual subtitles — single toggle.
  • Subtitles → Secondary translated subtitle — language picker (20 common
    languages).
  • The same language picker is also reachable from the in-player subtitle
    dialog and shows a warning if dual subtitles isn't enabled yet.

Settings persistence

Three new fields appended to the existing PlayerData serialization
(indices 63, 65, 66) — backwards-compatible with existing saved prefs.

@whyzgeek

Copy link
Copy Markdown
Author

I prepped this using AI and tested all worked on Android device and FireTV Stick

@whyzgeek whyzgeek changed the title Add dual subtitle playback with translation support. feat: Add dual subtitle playback with translation support. May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant