Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

## Unreleased

* 🐛 The language menu now prefers to show CEA-608/708 closed caption tracks with their localized language name (if available) instead of their language code (e.g. "en") or channel number (e.g. "CC1"). ([#84](https://github.com/THEOplayer/android-ui/pull/84))
* 🐛 The language menu now prefers to show CEA-608/708 closed caption tracks with their localized language name (if available) instead of their language code (e.g. "en") or channel number (e.g. "CC1"). ([#84](https://github.com/THEOplayer/android-ui/pull/84), [#95](https://github.com/THEOplayer/android-ui/pull/95))

## v1.13.3 (2026-03-23)

Expand Down
50 changes: 11 additions & 39 deletions ui/src/main/java/com/theoplayer/android/ui/util/TrackExts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ internal val Track.localizedLanguageName: String?

/**
* Constructs a label for the given [MediaTrack] instance.
*
* This returns the first non-empty entry from the list:
* 1. Track label
* 2. Track language display name
*/
internal fun constructLabel(track: MediaTrack<*>): String? {
return track.label?.takeUnless { it.isBlank() }
Expand All @@ -42,45 +38,21 @@ internal fun constructLabel(track: MediaTrack<*>): String? {

/**
* Constructs a label for the given [TextTrack] instance.
* The method works slightly different for different player version.
*
* On version 10 and below the logic checks the following and condition
* and the first not `null` entry from the list:
* 1. Track label if is not a language code
* or a CEA-prefixed string.
* 2. Track language display name
* 3. Track caption channel if a text CEA-608 track
* 4. Track label if was either a language code or a CEA-prefixed string
*
* If none of the above is satisfied, returns `null`.
*
* On version 11 and later the logic has slightly changed as
* the player no longer constructs the [Track.getLabel] internally:
* 1. Track label
* 2. Track language display name
* 3. Track caption channel
*/
internal fun constructLabel(track: TextTrack): String? {
val label: String? = if (
THEOplayerGlobalExt.version.major < 11 &&
(isLabelCeaFormatted(track.label) || (track.label != null && track.language == track.label))
) {
// If we are below 11th major release
// and the label is CEA-formatted we
// can safely assume it was the last resort
// option to produce a meaningful label, given
// we cannot localize the language code in the player.
null
} else {
// With 11 release, the player will no longer
// prefix text tracks with "CC" for CEA-608 and CEA-708,
// if [Track.label] is `null`.
track.label
val label = track.label?.takeIf {
when {
// Ignore empty labels.
it.isBlank() -> false
// Ignore default label with just the language code.
it == track.language -> false
// Ignore default label with just the caption channel.
(track.type == TextTrackType.CEA608 && isLabelCeaFormatted(it)) -> false
else -> true
}
}

if (!label.isNullOrBlank()) {
return label
}
label?.let { return it }

track.localizedLanguageName?.let { return it }

Expand Down
29 changes: 0 additions & 29 deletions ui/src/test/java/com/theoplayer/android/ui/util/TrackExtsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ class TrackExtsTest {

const val TEST_PLAYER_VERSION_10_0 = "10.0.0"
const val TEST_PLAYER_VERSION_10_13 = "10.13.0"
const val TEST_PLAYER_VERSION_11_0 = "11.0.0"

@JvmStatic
@Parameterized.Parameters(name = "{0}")
Expand Down Expand Up @@ -249,34 +248,6 @@ class TrackExtsTest {
playerVersion = TEST_PLAYER_VERSION_10_13,
expectedLabel = "CC4",
),

// v11.0 checks.
// - Track.captionChannel is always set
// - Track.label must not be "CC1" or "CC2"
Args(
label = "Hello world",
language = null,
localizedLanguageName = null,
captionChannel = 1,
playerVersion = TEST_PLAYER_VERSION_11_0,
expectedLabel = "Hello world",
),
Args(
label = "en",
language = "en",
localizedLanguageName = "English",
captionChannel = 1,
playerVersion = TEST_PLAYER_VERSION_11_0,
expectedLabel = "en",
),
Args(
label = null,
language = null,
localizedLanguageName = null,
captionChannel = 4,
playerVersion = TEST_PLAYER_VERSION_11_0,
expectedLabel = "CC4",
),
)
}
}
Expand Down