# Player subtitles, picture-in-picture and external players

Settings are stored in `DbSettings.features.player`. Defaults keep the
previous behavior.

## Subtitle selection

- Internal player settings include a language priority list, preferred
  (whitelist) names and excluded (blacklist) names. All are comma-separated.
- When a stream loads, excluded tracks are never auto-selected. The first
  listed language that still has a track wins. Codes match as words and English
  names match too ("en" or "English"). Preferred names win within that
  language.
- If no language matches, the first allowed track is used, as before. With no
  list, the legacy default subtitle language is used.
- mpv also receives the list as `slang` for embedded tracks. It is unset when
  the list is empty.

## Secondary subtitles

- The subtitle tab has a Secondary subtitle choice and its own delay.
- mpv adds the file with `sub-add … auto`, finds its id in `track-list` and
  sets `secondary-sid` and `secondary-sub-delay`. mpv draws it at the top.
- compose-mediaplayer (web, iOS simulator, Linux fallback) shows a second cue
  layer at the top, offset by the delay. Primary subtitles now render on this
  backend too.

## Screenshots with subtitles

- Off by default. "Include subtitles in screenshots" makes mpv capture with
  `screenshot-to-file … subtitles` instead of `video`.
- Screenshots remain mpv-only. Other backends keep the existing
  "unavailable" notice.

## Picture-in-picture

| Setting | Default | Effect |
|---|---|---|
| Picture-in-picture | On | Shows the PiP button and keeps automatic PiP when the app is left while playing. Off removes both. |
| PiP on exit | Off | Back while playing enters system PiP. Without it, the player shrinks to Yokan's mini player. |
| PiP episode notices | On | Shows the episode name when the episode changes while in PiP. |
| Replace +10 s with previous episode | Off | Sets the first PiP control. |

- **Android:** activity PiP with remote actions: +10 s or previous episode,
  play/pause, and next episode. Actions arrive through a non-exported
  receiver.
- **Web:** the browser's video PiP. Media Session handlers supply next track
  and either seek-forward or previous track.
- **iOS and desktop:** no system PiP. mpv renders through its own layer, so
  `AVPictureInPictureController`, which needs an AVPlayer layer, cannot host it.
  PiP on exit uses the in-app mini player.

## External player

- Choose an External player and turn on Always use external player. The
  episode's first stream is then handed over when it loads, and the player
  closes. If launching fails, playback stays in-app with a notice.
- Header-requiring streams use the local proxy, as before.
- **Android:** installed apps that handle `video/*`. The package is set on the
  intent; `<queries>` in the manifest lists them.
- **Desktop:** mpv (with headers), IINA or VLC, depending on OS and what is
  installed, or the system handler.
- **iOS:** VLC, Infuse and Outplayer URL schemes (`LSApplicationQueriesSchemes`),
  or the system handler.
- **Web:** blocked. Browsers cannot launch native apps with a stream URL, so
  settings say so and the option is hidden.

## Verification

2026-10-18: `PlaybackPoliciesTest` covers priority, whitelist, blacklist and
fallback selection. `MpvFeaturesTest` covers `slang`, subtitle screenshots,
`secondary-sub-delay` and volume commands. `ComposeControllerRetirementTest`
covers track and error reset and retirement. All passed on desktop JVM and
Kotlin/Wasm. Android, iOS simulator, desktop and Wasm compiled.
