Commit fdbea33a by olly Committed by Oliver Woodman

Improve track naming when sampleMimeType unset

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=195346555
parent bef4a20c
...@@ -22,7 +22,6 @@ import com.google.android.exoplayer2.Format; ...@@ -22,7 +22,6 @@ import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import java.util.Locale; import java.util.Locale;
/** A default {@link TrackNameProvider}. */ /** A default {@link TrackNameProvider}. */
...@@ -38,9 +37,10 @@ public class DefaultTrackNameProvider implements TrackNameProvider { ...@@ -38,9 +37,10 @@ public class DefaultTrackNameProvider implements TrackNameProvider {
@Override @Override
public String getTrackName(Format format) { public String getTrackName(Format format) {
String trackName; String trackName;
if (MimeTypes.isVideo(format.sampleMimeType)) { int trackType = inferPrimaryTrackType(format);
if (trackType == C.TRACK_TYPE_VIDEO) {
trackName = joinWithSeparator(buildResolutionString(format), buildBitrateString(format)); trackName = joinWithSeparator(buildResolutionString(format), buildBitrateString(format));
} else if (MimeTypes.isAudio(format.sampleMimeType)) { } else if (trackType == C.TRACK_TYPE_AUDIO) {
trackName = trackName =
joinWithSeparator( joinWithSeparator(
buildLanguageString(format), buildLanguageString(format),
...@@ -112,4 +112,24 @@ public class DefaultTrackNameProvider implements TrackNameProvider { ...@@ -112,4 +112,24 @@ public class DefaultTrackNameProvider implements TrackNameProvider {
} }
return itemList; return itemList;
} }
private static int inferPrimaryTrackType(Format format) {
int trackType = MimeTypes.getTrackType(format.sampleMimeType);
if (trackType != C.TRACK_TYPE_UNKNOWN) {
return trackType;
}
if (MimeTypes.getVideoMediaMimeType(format.codecs) != null) {
return C.TRACK_TYPE_VIDEO;
}
if (MimeTypes.getAudioMediaMimeType(format.codecs) != null) {
return C.TRACK_TYPE_AUDIO;
}
if (format.width != Format.NO_VALUE || format.height != Format.NO_VALUE) {
return C.TRACK_TYPE_VIDEO;
}
if (format.channelCount != Format.NO_VALUE || format.sampleRate != Format.NO_VALUE) {
return C.TRACK_TYPE_AUDIO;
}
return C.TRACK_TYPE_UNKNOWN;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment