Skip to content

fix: name the tracks the audio and subtitle menus offer - #142

Merged
itsjoshpark merged 1 commit into
mainfrom
fix/name-media-tracks
Aug 24, 2026
Merged

fix: name the tracks the audio and subtitle menus offer#142
itsjoshpark merged 1 commit into
mainfrom
fix/name-media-tracks

Conversation

@itsjoshpark

Copy link
Copy Markdown
Owner

Problem

Two complaints, one cause — the menus repeated whatever media selection handed back.

File Audio Track menu Now
Front Row > Play Spatial Audio Sample None Off / Track 1
An untagged MP4 Unknown language Off / Track 1

Why "None". AVFoundation only synthesises a media selection group for a file-based asset when the container's tracks carry a non-zero alternate_group. The Dolby sample's are all 0:

File video audio subtitle
a tagged MP4 0 1 3
Dolby sample 0 0

Not a streaming problem — a local copy of the sample behaves identically, and AVPlayerItem.tracks plainly carries its 6-channel E-AC-3 track. Any MP4 in group 0 hits this, which is why the Inspector's Tracks tab listed tracks for files whose menus said "None".

Why "Unknown language". Locale.current.localizedString(forIdentifier: "und") is "Unknown language". AVFoundation was rendering the marker a container writes for a track nobody tagged, not describing the track.

Change

  • Where no media selection group exists, both menus fall back to the asset's tracks and switch by enabling the matching AVPlayerItemTrack. Media selection stays preferred wherever it exists.
  • One naming rule for both mechanisms: title qualified by language → language → Track N. und counts as untagged.

Checked against measured behaviour so well-described options survive — probing a hand-built HLS stream, a rendition's NAME arrives as common metadata and a CC option carries a nil tag rather than und, so "Commentary", "CC" and "English Forced" are all kept.

Verification

  • 282 unit tests pass; analyze and swift-format lint clean.
  • Driven in the real app: the sample now lists Off / Track 1 with Track 1 checked. Choosing Off dims Playing on the audio track in the Inspector and choosing Track 1 lights it again — the track-enabling path working end to end.
  • Regression check on the media-selection path: the tagged MP4 lists Off / English with English Forced filtered out, and subtitles render on screen.

New source strings %@ (%@) and Track %lld are added untranslated for Crowdin.

The menus were built only from AVFoundation's media selection groups, which
left them saying two wrong things.

A file whose tracks sit in no alternate group gets no media selection group at
all, so both menus read "None" even though the file plainly has tracks - which
is what Front Row > Play Spatial Audio Sample did, and what the Inspector's
Tracks tab contradicted. Where no group exists, the menus now fall back to the
asset's own tracks and switch between them by enabling the matching player item
track. Media selection is still preferred wherever it exists, since it is what
HTTP Live Streaming and well-tagged files describe themselves with.

An untagged track was named "Unknown language", which is the `und` marker
rendered as text rather than anything about the track. One rule now names every
entry in both menus: the track's own title qualified by its language, else the
language, else its number. An HLS rendition's NAME arrives as a title and a
caption option carries no tag at all, so both keep the names they had.
@itsjoshpark
itsjoshpark merged commit d9c8184 into main Aug 24, 2026
2 checks passed
@itsjoshpark
itsjoshpark deleted the fix/name-media-tracks branch August 24, 2026 19:58
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