fix(player): send subtitle tracks to ExoPlayer on Android (UR-020)
Selecting a subtitle on Android did nothing. The Kotlin side has been
complete for a long time — JellyTauPlayer.load() parses a subtitles JSON
array into MediaItem.SubtitleConfigurations and setSubtitleTrack() drives a
TrackSelectionOverride — but nothing ever reached it.
VideoPlayer built the list and then threw it away: it resolved every
subtitle stream's URL into a subtitleTracks array and the
commands.playerPlayItem({...}) call two lines below passed only streamUrl,
title, id, videoCodec and needsTranscoding. PlayItemRequest had no subtitle
field to put them in, so create_media_item hardcoded subtitles: vec![],
android/mod.rs serialized "[]" across JNI, and every MediaItem reached
ExoPlayer with zero SubtitleConfigurations. A later set_subtitle_track then
found no text track groups and logged "Invalid subtitle track index".
PlayItemRequest now carries the tracks (defaulted, so the background-audio
handoff and next-episode callers are unchanged) and create_media_item
threads them onto the MediaItem.
Serialization: SubtitleTrack is reused verbatim rather than given an
IPC-specific twin, and deliberately keeps snake_case. The same struct feeds
two consumers that both spell mime_type — the JNI JSON that
JellyTauPlayer.load() reads with optString("mime_type"), and the generated
binding the frontend types against. camelCasing it would not fail the build
or the IPC; Kotlin would silently fall back to its default MIME type for
every track. UT-146 asserts the exact serialized keys so a future
rename_all cannot pass unnoticed.
The index mapping was NOT already correct. setSubtitleTrack(n) indexes
ExoPlayer's filtered text track groups, i.e. the position of the sideloaded
configuration — but the menu passed its own {#each} row number, which counts
every subtitle *stream*, including ones whose URL failed to resolve and were
therefore never sideloaded. One failed URL and every track below it selected
the wrong subtitle. The position is now looked up in the exact array that
was sent (nativeSubtitleArrayIndex), and a stream that was never sent maps
to "off" rather than to a guessed position.
The resolution loop also reuses resolveSubtitleTracks() from the Linux fix
instead of duplicating it, which fans the URL requests out in parallel
rather than awaiting them one per stream before playback can start. The
awaits are safe where they sit: the native-mode pitfall is about Svelte
lifecycle calls after an await, and nothing is registered here — the
background-audio subscriptions above still run synchronously.
No Kotlin change was needed.
Tests (UT-145, UT-146, UT-147) were written first and failed: PlayItemRequest
had no subtitles field to compile against, nativeSubtitleTracks and
nativeSubtitleArrayIndex did not exist, and the playerPlayItem call carried
no subtitles key.
TRACES: UR-020 | IR-016, JA-008 | UT-145, UT-146, UT-147
This commit is contained in:
@@ -23,6 +23,23 @@ pub enum QueueContext {
|
||||
}
|
||||
|
||||
/// Represents a subtitle track
|
||||
///
|
||||
/// 🔴 **Do not add `#[serde(rename_all = "camelCase")]` here.** This is the one
|
||||
/// struct in the player that deliberately keeps snake_case on the wire, because
|
||||
/// the *same* serialization feeds two consumers that both spell `mime_type`:
|
||||
///
|
||||
/// * the JNI boundary — `player/android/mod.rs` serializes `MediaItem::subtitles`
|
||||
/// with `serde_json` and hands the string to `JellyTauPlayer.loadWithMetadata`,
|
||||
/// whose parser reads `url`, `language`, `label` and `optString("mime_type")`;
|
||||
/// * the IPC boundary — `PlayItemRequest::subtitles` deserializes this same type
|
||||
/// from the frontend, and the generated binding (`SubtitleTrack` in
|
||||
/// `bindings.ts`) therefore also declares `mime_type`.
|
||||
///
|
||||
/// Renaming would not break the build and would not fail the IPC: Kotlin's
|
||||
/// `optString` would just fall back to its default MIME type for every track, so
|
||||
/// the failure would be silent. UT-146 asserts the serialized keys.
|
||||
///
|
||||
/// TRACES: UR-020 | IR-016, JA-008 | UT-146
|
||||
#[derive(specta::Type, Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct SubtitleTrack {
|
||||
/// Stream index in the media source
|
||||
@@ -33,7 +50,8 @@ pub struct SubtitleTrack {
|
||||
pub language: Option<String>,
|
||||
/// Display title
|
||||
pub label: Option<String>,
|
||||
/// MIME type (e.g., "text/vtt", "application/x-subrip")
|
||||
/// MIME type (e.g., "text/vtt", "application/x-subrip").
|
||||
/// Snake_case on purpose — see the note on the struct.
|
||||
pub mime_type: String,
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ pub mod webview_audio_backend;
|
||||
pub use autoplay::{AutoplayDecision, AutoplaySettings};
|
||||
pub use backend::{NullBackend, PlayerBackend, PlayerError};
|
||||
pub use events::{PlayerEventEmitter, PlayerStatusEvent, TauriEventEmitter};
|
||||
pub use media::{MediaItem, MediaSource, MediaType, QueueContext};
|
||||
pub use media::{MediaItem, MediaSource, MediaType, QueueContext, SubtitleTrack};
|
||||
pub use queue::{QueueManager, RepeatMode};
|
||||
pub use seek::{determine_video_seek_strategy, VideoSeekStrategy};
|
||||
pub use session::{MediaSessionManager, MediaSessionType};
|
||||
|
||||
Reference in New Issue
Block a user