Skip to content

Commit

Permalink
Fallback to including track language name if display name is not found
Browse files Browse the repository at this point in the history
Issue: androidx#988
PiperOrigin-RevId: 606193299
(cherry picked from commit 0b0c419)
  • Loading branch information
microkatz authored and l1068 committed Apr 15, 2024
1 parent 0cf4afe commit ae53d0e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
4 changes: 4 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

* Effect:
* Improved PQ to SDR tone-mapping by converting color spaces.
* UI:
* Fallback to include audio track language name if `Locale` cannot
identify a display name
([#988](https://github.com/androidx/media/issues/988)).

## 1.3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ public String getTrackName(Format format) {
} else {
trackName = buildLanguageOrLabelString(format);
}
return trackName.length() == 0 ? resources.getString(R.string.exo_track_unknown) : trackName;
if (trackName.length() != 0) {
return trackName;
}
@Nullable String language = format.language;
return (language == null || language.trim().isEmpty())
? resources.getString(R.string.exo_track_unknown)
: resources.getString(R.string.exo_track_unknown_name, language);
}

private String buildResolutionString(Format format) {
Expand Down
2 changes: 2 additions & 0 deletions libraries/ui/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@
<string name="exo_track_selection_auto">Auto</string>
<!-- Name of a media track about which nothing is known. Shown in a list view that allows the user to choose between multiple media tracks. [CHAR LIMIT=20] -->
<string name="exo_track_unknown">Unknown</string>
<!-- Name of a media track of which the language name could not be identified. Shown in a list view that allows the user to choose between multiple media tracks. [CHAR LIMIT=20] -->
<string name="exo_track_unknown_name">Unknown (<xliff:g id="name" example="Frengligian">%1$s</xliff:g>)</string>
<!-- Resolution of a video track. [CHAR LIMIT=20] -->
<string name="exo_track_resolution"><xliff:g id="width" example="1024">%1$d</xliff:g> × <xliff:g id="height" example="768">%2$d</xliff:g></string>
<!-- Describes an audio track with one channel. Shown in a list view that allows the user to choose between multiple audio tracks. [CHAR LIMIT=20] -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,46 @@
public class DefaultTrackNameProviderTest {

@Test
public void getTrackName_handlesInvalidLanguage() {
public void getTrackName_withInvalidLanguage_returnsUnknownWithLanguage() {
Resources resources = ApplicationProvider.getApplicationContext().getResources();
DefaultTrackNameProvider provider = new DefaultTrackNameProvider(resources);
Format format = new Format.Builder().setLanguage("```").build();

String name = provider.getTrackName(format);

assertThat(name).isEqualTo(resources.getString(R.string.exo_track_unknown_name, "```"));
}

@Test
public void getTrackName_withLanguageEmptyString_returnsUnknown() {
Resources resources = ApplicationProvider.getApplicationContext().getResources();
DefaultTrackNameProvider provider = new DefaultTrackNameProvider(resources);
Format format = new Format.Builder().setLanguage("").build();

String name = provider.getTrackName(format);

assertThat(name).isEqualTo(resources.getString(R.string.exo_track_unknown));
}

@Test
public void getTrackName_withLanguageSpacesNewLine_returnsUnknown() {
Resources resources = ApplicationProvider.getApplicationContext().getResources();
DefaultTrackNameProvider provider = new DefaultTrackNameProvider(resources);
Format format = new Format.Builder().setLanguage(" \n ").build();

String name = provider.getTrackName(format);

assertThat(name).isEqualTo(resources.getString(R.string.exo_track_unknown));
}

@Test
public void getTrackName_withLanguageEmptyStringAndLabel_returnsLabel() {
Resources resources = ApplicationProvider.getApplicationContext().getResources();
DefaultTrackNameProvider provider = new DefaultTrackNameProvider(resources);
Format format = new Format.Builder().setLanguage("").setLabel("Main").build();

String name = provider.getTrackName(format);

assertThat(name).isEqualTo("Main");
}
}

0 comments on commit ae53d0e

Please sign in to comment.