mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Move utility methods to DemoUtil from TrackSelectionHelper
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=151706338
This commit is contained in:
parent
cc1a8f4034
commit
a473e7300c
2 changed files with 87 additions and 58 deletions
|
|
@ -0,0 +1,86 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2017 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.google.android.exoplayer2.demo;
|
||||||
|
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import com.google.android.exoplayer2.Format;
|
||||||
|
import com.google.android.exoplayer2.util.MimeTypes;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility methods for demo application.
|
||||||
|
*/
|
||||||
|
/*package*/ final class DemoUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds a track name for display.
|
||||||
|
*
|
||||||
|
* @param format {@link Format} of the track.
|
||||||
|
* @return a generated name specific to the track.
|
||||||
|
*/
|
||||||
|
public static String buildTrackName(Format format) {
|
||||||
|
String trackName;
|
||||||
|
if (MimeTypes.isVideo(format.sampleMimeType)) {
|
||||||
|
trackName = joinWithSeparator(joinWithSeparator(joinWithSeparator(
|
||||||
|
buildResolutionString(format), buildBitrateString(format)), buildTrackIdString(format)),
|
||||||
|
buildSampleMimeTypeString(format));
|
||||||
|
} else if (MimeTypes.isAudio(format.sampleMimeType)) {
|
||||||
|
trackName = joinWithSeparator(joinWithSeparator(joinWithSeparator(joinWithSeparator(
|
||||||
|
buildLanguageString(format), buildAudioPropertyString(format)),
|
||||||
|
buildBitrateString(format)), buildTrackIdString(format)),
|
||||||
|
buildSampleMimeTypeString(format));
|
||||||
|
} else {
|
||||||
|
trackName = joinWithSeparator(joinWithSeparator(joinWithSeparator(buildLanguageString(format),
|
||||||
|
buildBitrateString(format)), buildTrackIdString(format)),
|
||||||
|
buildSampleMimeTypeString(format));
|
||||||
|
}
|
||||||
|
return trackName.length() == 0 ? "unknown" : trackName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String buildResolutionString(Format format) {
|
||||||
|
return format.width == Format.NO_VALUE || format.height == Format.NO_VALUE
|
||||||
|
? "" : format.width + "x" + format.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String buildAudioPropertyString(Format format) {
|
||||||
|
return format.channelCount == Format.NO_VALUE || format.sampleRate == Format.NO_VALUE
|
||||||
|
? "" : format.channelCount + "ch, " + format.sampleRate + "Hz";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String buildLanguageString(Format format) {
|
||||||
|
return TextUtils.isEmpty(format.language) || "und".equals(format.language) ? ""
|
||||||
|
: format.language;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String buildBitrateString(Format format) {
|
||||||
|
return format.bitrate == Format.NO_VALUE ? ""
|
||||||
|
: String.format(Locale.US, "%.2fMbit", format.bitrate / 1000000f);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String joinWithSeparator(String first, String second) {
|
||||||
|
return first.length() == 0 ? second : (second.length() == 0 ? first : first + ", " + second);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String buildTrackIdString(Format format) {
|
||||||
|
return format.id == null ? "" : ("id:" + format.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String buildSampleMimeTypeString(Format format) {
|
||||||
|
return format.sampleMimeType == null ? "" : format.sampleMimeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
private DemoUtil() {}
|
||||||
|
}
|
||||||
|
|
@ -21,13 +21,11 @@ import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.CheckedTextView;
|
import android.widget.CheckedTextView;
|
||||||
import com.google.android.exoplayer2.Format;
|
|
||||||
import com.google.android.exoplayer2.RendererCapabilities;
|
import com.google.android.exoplayer2.RendererCapabilities;
|
||||||
import com.google.android.exoplayer2.source.TrackGroup;
|
import com.google.android.exoplayer2.source.TrackGroup;
|
||||||
import com.google.android.exoplayer2.source.TrackGroupArray;
|
import com.google.android.exoplayer2.source.TrackGroupArray;
|
||||||
|
|
@ -37,9 +35,7 @@ import com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedT
|
||||||
import com.google.android.exoplayer2.trackselection.MappingTrackSelector.SelectionOverride;
|
import com.google.android.exoplayer2.trackselection.MappingTrackSelector.SelectionOverride;
|
||||||
import com.google.android.exoplayer2.trackselection.RandomTrackSelection;
|
import com.google.android.exoplayer2.trackselection.RandomTrackSelection;
|
||||||
import com.google.android.exoplayer2.trackselection.TrackSelection;
|
import com.google.android.exoplayer2.trackselection.TrackSelection;
|
||||||
import com.google.android.exoplayer2.util.MimeTypes;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class for displaying track selection dialogs.
|
* Helper class for displaying track selection dialogs.
|
||||||
|
|
@ -157,7 +153,7 @@ import java.util.Locale;
|
||||||
CheckedTextView trackView = (CheckedTextView) inflater.inflate(
|
CheckedTextView trackView = (CheckedTextView) inflater.inflate(
|
||||||
trackViewLayoutId, root, false);
|
trackViewLayoutId, root, false);
|
||||||
trackView.setBackgroundResource(selectableItemBackgroundResourceId);
|
trackView.setBackgroundResource(selectableItemBackgroundResourceId);
|
||||||
trackView.setText(buildTrackName(group.getFormat(trackIndex)));
|
trackView.setText(DemoUtil.buildTrackName(group.getFormat(trackIndex)));
|
||||||
if (trackInfo.getTrackFormatSupport(rendererIndex, groupIndex, trackIndex)
|
if (trackInfo.getTrackFormatSupport(rendererIndex, groupIndex, trackIndex)
|
||||||
== RendererCapabilities.FORMAT_HANDLED) {
|
== RendererCapabilities.FORMAT_HANDLED) {
|
||||||
trackView.setFocusable(true);
|
trackView.setFocusable(true);
|
||||||
|
|
@ -296,57 +292,4 @@ import java.util.Locale;
|
||||||
return tracks;
|
return tracks;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Track name construction.
|
|
||||||
|
|
||||||
private static String buildTrackName(Format format) {
|
|
||||||
String trackName;
|
|
||||||
if (MimeTypes.isVideo(format.sampleMimeType)) {
|
|
||||||
trackName = joinWithSeparator(joinWithSeparator(joinWithSeparator(
|
|
||||||
buildResolutionString(format), buildBitrateString(format)), buildTrackIdString(format)),
|
|
||||||
buildSampleMimeTypeString(format));
|
|
||||||
} else if (MimeTypes.isAudio(format.sampleMimeType)) {
|
|
||||||
trackName = joinWithSeparator(joinWithSeparator(joinWithSeparator(joinWithSeparator(
|
|
||||||
buildLanguageString(format), buildAudioPropertyString(format)),
|
|
||||||
buildBitrateString(format)), buildTrackIdString(format)),
|
|
||||||
buildSampleMimeTypeString(format));
|
|
||||||
} else {
|
|
||||||
trackName = joinWithSeparator(joinWithSeparator(joinWithSeparator(buildLanguageString(format),
|
|
||||||
buildBitrateString(format)), buildTrackIdString(format)),
|
|
||||||
buildSampleMimeTypeString(format));
|
|
||||||
}
|
|
||||||
return trackName.length() == 0 ? "unknown" : trackName;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String buildResolutionString(Format format) {
|
|
||||||
return format.width == Format.NO_VALUE || format.height == Format.NO_VALUE
|
|
||||||
? "" : format.width + "x" + format.height;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String buildAudioPropertyString(Format format) {
|
|
||||||
return format.channelCount == Format.NO_VALUE || format.sampleRate == Format.NO_VALUE
|
|
||||||
? "" : format.channelCount + "ch, " + format.sampleRate + "Hz";
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String buildLanguageString(Format format) {
|
|
||||||
return TextUtils.isEmpty(format.language) || "und".equals(format.language) ? ""
|
|
||||||
: format.language;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String buildBitrateString(Format format) {
|
|
||||||
return format.bitrate == Format.NO_VALUE ? ""
|
|
||||||
: String.format(Locale.US, "%.2fMbit", format.bitrate / 1000000f);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String joinWithSeparator(String first, String second) {
|
|
||||||
return first.length() == 0 ? second : (second.length() == 0 ? first : first + ", " + second);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String buildTrackIdString(Format format) {
|
|
||||||
return format.id == null ? "" : ("id:" + format.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String buildSampleMimeTypeString(Format format) {
|
|
||||||
return format.sampleMimeType == null ? "" : format.sampleMimeType;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue