Use role flags in DefaultTrackNameProvider.

Also make combination of language and role flags the default over the label,
as it's more readable and auto-translated into other languages.

PiperOrigin-RevId: 240801070
This commit is contained in:
tonihei 2019-03-28 17:30:25 +00:00 committed by Toni
parent 28ea31cd4c
commit 32924e3f17
2 changed files with 44 additions and 13 deletions

View file

@ -39,15 +39,17 @@ public class DefaultTrackNameProvider implements TrackNameProvider {
String trackName;
int trackType = inferPrimaryTrackType(format);
if (trackType == C.TRACK_TYPE_VIDEO) {
trackName = joinWithSeparator(buildResolutionString(format), buildBitrateString(format));
trackName =
joinWithSeparator(
buildRoleString(format), buildResolutionString(format), buildBitrateString(format));
} else if (trackType == C.TRACK_TYPE_AUDIO) {
trackName =
joinWithSeparator(
buildLabelString(format),
buildLanguageOrLabelString(format),
buildAudioChannelString(format),
buildBitrateString(format));
} else {
trackName = buildLabelString(format);
trackName = buildLanguageOrLabelString(format);
}
return trackName.length() == 0 ? resources.getString(R.string.exo_track_unknown) : trackName;
}
@ -87,22 +89,43 @@ public class DefaultTrackNameProvider implements TrackNameProvider {
}
}
private String buildLabelString(Format format) {
if (!TextUtils.isEmpty(format.label)) {
return format.label;
}
// Fall back to using the language.
String language = format.language;
return TextUtils.isEmpty(language) || C.LANGUAGE_UNDETERMINED.equals(language)
? ""
: buildLanguageString(language);
private String buildLanguageOrLabelString(Format format) {
String languageAndRole =
joinWithSeparator(buildLanguageString(format), buildRoleString(format));
return TextUtils.isEmpty(languageAndRole) ? buildLabelString(format) : languageAndRole;
}
private String buildLanguageString(String language) {
private String buildLabelString(Format format) {
return TextUtils.isEmpty(format.label) ? "" : format.label;
}
private String buildLanguageString(Format format) {
String language = format.language;
if (TextUtils.isEmpty(language) || C.LANGUAGE_UNDETERMINED.equals(language)) {
return "";
}
Locale locale = Util.SDK_INT >= 21 ? Locale.forLanguageTag(language) : new Locale(language);
return locale.getDisplayName();
}
private String buildRoleString(Format format) {
String roles = "";
if ((format.roleFlags & C.ROLE_FLAG_ALTERNATE) != 0) {
roles = resources.getString(R.string.exo_track_role_alternate);
}
if ((format.roleFlags & C.ROLE_FLAG_SUPPLEMENTARY) != 0) {
roles = joinWithSeparator(roles, resources.getString(R.string.exo_track_role_supplementary));
}
if ((format.roleFlags & C.ROLE_FLAG_COMMENTARY) != 0) {
roles = joinWithSeparator(roles, resources.getString(R.string.exo_track_role_commentary));
}
if ((format.roleFlags & (C.ROLE_FLAG_CAPTION | C.ROLE_FLAG_DESCRIBES_MUSIC_AND_SOUND)) != 0) {
roles =
joinWithSeparator(roles, resources.getString(R.string.exo_track_role_closed_captions));
}
return roles;
}
private String joinWithSeparator(String... items) {
String itemList = "";
for (String item : items) {

View file

@ -76,6 +76,14 @@
<string name="exo_track_surround_5_point_1">5.1 surround sound</string>
<!-- Describes a 7.1 (https://en.wikipedia.org/wiki/7.1_surround_sound) audio track. [CHAR LIMIT=40] -->
<string name="exo_track_surround_7_point_1">7.1 surround sound</string>
<!-- Describes an alternate track, e.g. a video recorded from a different viewpoint. [CHAR LIMIT=40] -->
<string name="exo_track_role_alternate">Alternate</string>
<!-- Describes a supplementary track. [CHAR LIMIT=40] -->
<string name="exo_track_role_supplementary">Supplementary</string>
<!-- Describes a track containing commentary. [CHAR LIMIT=40] -->
<string name="exo_track_role_commentary">Commentary</string>
<!-- Describes a track with closed captions. [CHAR LIMIT=40] -->
<string name="exo_track_role_closed_captions">CC</string>
<!-- Describes the bitrate of a media track in Megabits (https://en.wikipedia.org/wiki/Megabit) per second. [CHAR LIMIT=20] -->
<string name="exo_track_bitrate"><xliff:g id="bitrate" example="5.2">%1$.2f</xliff:g> Mbps</string>
<!-- Defines a way of appending an item to a list of items. For example appending "banana" to "apple, pear" to get "apple, pear, banana". Note: the command separator will appear between all consecutive list items, so do not use an equivalent of 'and'. [CHAR LIMIT=40] -->