mirror of
https://github.com/mediathekview/zapp.git
synced 2024-09-20 20:23:04 +02:00
- implemented CustomTrackNameProvider
- added CustomTrackNameProvider to TrackSelectionView - removed unused sort methods
This commit is contained in:
parent
9bbe9991cf
commit
472b0d3d9c
@ -0,0 +1,140 @@
|
||||
package de.christinecoenen.code.zapp.app.player;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.text.TextUtils;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.ui.DefaultTrackNameProvider;
|
||||
import com.google.android.exoplayer2.util.MimeTypes;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import de.christinecoenen.code.zapp.R;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
public class CustomTrackNameProvider extends DefaultTrackNameProvider {
|
||||
|
||||
private final Resources resources;
|
||||
private Format tempFormat = null;
|
||||
|
||||
/**
|
||||
* @param resources Resources from which to obtain strings.
|
||||
*/
|
||||
CustomTrackNameProvider(Resources resources) {
|
||||
super(resources);
|
||||
this.resources = resources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTrackName(Format format) {
|
||||
String trackName;
|
||||
int trackType = inferPrimaryTrackType(format);
|
||||
if (trackType == C.TRACK_TYPE_VIDEO) {
|
||||
trackName = joinWithSeparator(buildResolutionString(format), buildBitrateString(format));
|
||||
} else if (trackType == C.TRACK_TYPE_AUDIO) {
|
||||
trackName =
|
||||
joinWithSeparator(
|
||||
buildLabelString(format),
|
||||
buildAudioChannelString(format),
|
||||
buildBitrateString(format));
|
||||
} else {
|
||||
trackName = buildLabelString(format);
|
||||
}
|
||||
|
||||
if (tempFormat != null && tempFormat.bitrate == format.bitrate) {
|
||||
tempFormat = format;
|
||||
return trackName.length() == 0 ? resources.getString(R.string.exo_track_unknown)
|
||||
: trackName + " " + resources.getString(R.string.video_format_fallback);
|
||||
|
||||
} else {
|
||||
tempFormat = format;
|
||||
return trackName.length() == 0 ? resources.getString(R.string.exo_track_unknown) : trackName;
|
||||
}
|
||||
}
|
||||
|
||||
private String buildResolutionString(Format format) {
|
||||
int width = format.width;
|
||||
int height = format.height;
|
||||
return width == Format.NO_VALUE || height == Format.NO_VALUE
|
||||
? ""
|
||||
: resources.getString(R.string.exo_track_resolution, width, height);
|
||||
}
|
||||
|
||||
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 buildLanguageString(String language) {
|
||||
Locale locale = Util.SDK_INT >= 21 ? Locale.forLanguageTag(language) : new Locale(language);
|
||||
return locale.getDisplayLanguage();
|
||||
}
|
||||
|
||||
private String buildAudioChannelString(Format format) {
|
||||
int channelCount = format.channelCount;
|
||||
if (channelCount == Format.NO_VALUE || channelCount < 1) {
|
||||
return "";
|
||||
}
|
||||
switch (channelCount) {
|
||||
case 1:
|
||||
return resources.getString(R.string.exo_track_mono);
|
||||
case 2:
|
||||
return resources.getString(R.string.exo_track_stereo);
|
||||
case 6:
|
||||
case 7:
|
||||
return resources.getString(R.string.exo_track_surround_5_point_1);
|
||||
case 8:
|
||||
return resources.getString(R.string.exo_track_surround_7_point_1);
|
||||
default:
|
||||
return resources.getString(R.string.exo_track_surround);
|
||||
}
|
||||
}
|
||||
|
||||
private String buildBitrateString(Format format) {
|
||||
int bitrate = format.bitrate;
|
||||
return bitrate == Format.NO_VALUE
|
||||
? ""
|
||||
: resources.getString(R.string.exo_track_bitrate, bitrate / 1000000f);
|
||||
}
|
||||
|
||||
private String joinWithSeparator(String... items) {
|
||||
String itemList = "";
|
||||
for (String item : items) {
|
||||
if (item.length() > 0) {
|
||||
if (TextUtils.isEmpty(itemList)) {
|
||||
itemList = item;
|
||||
} else {
|
||||
itemList = resources.getString(R.string.exo_item_list, itemList, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -38,8 +38,6 @@ import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import timber.log.Timber;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Player {
|
||||
|
||||
private final static String SUBTITLE_LANGUAGE_ON = "deu";
|
||||
@ -178,12 +176,12 @@ public class Player {
|
||||
}
|
||||
|
||||
public void showQualitySettingsDialog(Activity activity) {
|
||||
overrideVideoTrackGroup(trackSelector);
|
||||
MappingTrackSelector.MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo();
|
||||
if (mappedTrackInfo != null) {
|
||||
int rendererIndex = getVideoRendererIndex(trackSelector);
|
||||
Pair<AlertDialog, TrackSelectionView> dialogPair =
|
||||
TrackSelectionView.getDialog(activity, activity.getString(R.string.video_quality), trackSelector, rendererIndex);
|
||||
dialogPair.second.setTrackNameProvider(new CustomTrackNameProvider(activity.getResources()));
|
||||
dialogPair.first.show();
|
||||
}
|
||||
}
|
||||
@ -202,51 +200,6 @@ public class Player {
|
||||
return videoRendererIndex;
|
||||
}
|
||||
|
||||
private void overrideVideoTrackGroup (DefaultTrackSelector trackSelector) {
|
||||
int videoRendererIndex = getVideoRendererIndex(trackSelector);
|
||||
TrackGroup sortedVideoTrackGroup = getSortedVideoTrackGroup(getSortedFormatArrayList(trackSelector));
|
||||
TrackGroupArray sortedVideoTrackgroupArray = new TrackGroupArray(sortedVideoTrackGroup);
|
||||
DefaultTrackSelector.ParametersBuilder builder = trackSelector.getParameters().buildUpon();
|
||||
|
||||
}
|
||||
|
||||
private TrackGroup getSortedVideoTrackGroup(@NonNull ArrayList<Format> formatList) {
|
||||
Format [] formats = new Format[formatList.size()];
|
||||
for (int i = 0; i < formatList.size(); i++) {
|
||||
formats[i] = formatList.get(i);
|
||||
}
|
||||
return new TrackGroup(formats);
|
||||
}
|
||||
|
||||
private ArrayList<Format> getSortedFormatArrayList(DefaultTrackSelector trackSelector) {
|
||||
ArrayList<Format> formatArrayList = new ArrayList<>();
|
||||
Format tempFormat = null;
|
||||
MappingTrackSelector.MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo();
|
||||
if (mappedTrackInfo != null) {
|
||||
for (int trackGroups = 0; trackGroups < mappedTrackInfo.getRendererCount(); trackGroups++) {
|
||||
TrackGroupArray trackGroupArray = mappedTrackInfo.getTrackGroups(trackGroups);
|
||||
if (trackGroupArray.length != 0 && player.getRendererType(trackGroups) == C.TRACK_TYPE_VIDEO) {
|
||||
//Trackgroup Array für videos auslesen
|
||||
for (int j = 0; j < trackGroupArray.length; j++) {
|
||||
TrackGroup trackGroup = trackGroupArray.get(j);
|
||||
for (int k = 0; k < trackGroup.length; k++) {
|
||||
Format format = trackGroup.getFormat(k);
|
||||
if (tempFormat == null) {
|
||||
tempFormat = format;
|
||||
} else {
|
||||
if (tempFormat.bitrate != format.bitrate) {
|
||||
formatArrayList.add(format);
|
||||
tempFormat = format;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return formatArrayList;
|
||||
}
|
||||
|
||||
public Observable<Integer> getErrorResourceId() {
|
||||
return Observable.combineLatest(
|
||||
playerEventHandler.getErrorResourceId(),
|
||||
|
@ -71,6 +71,8 @@
|
||||
<!-- player -->
|
||||
<string name="player_zoom_state_cropped">Zoomed</string>
|
||||
<string name="player_zoom_state_boxed">Original</string>
|
||||
<string name="video_quality">Quality</string>
|
||||
<string name="video_format_fallback">(Fallback)</string>
|
||||
|
||||
|
||||
<!-- paperboy changelog -->
|
||||
@ -103,5 +105,4 @@
|
||||
|
||||
<!-- notifications -->
|
||||
<string name="notification_channel_name_background_playback">Background player</string>
|
||||
<string name="video_quality">Quality</string>
|
||||
</resources>
|
||||
|
@ -71,6 +71,8 @@
|
||||
<!-- player -->
|
||||
<string name="player_zoom_state_cropped">Gezoomt</string>
|
||||
<string name="player_zoom_state_boxed">Original</string>
|
||||
<string name="video_quality">Qualität</string>
|
||||
<string name="video_format_fallback">(Ersatz)</string>
|
||||
|
||||
|
||||
<!-- paperboy changelog -->
|
||||
@ -103,5 +105,4 @@
|
||||
|
||||
<!-- notifications -->
|
||||
<string name="notification_channel_name_background_playback">Hintergrund-Videoplayer</string>
|
||||
<string name="video_quality">Qualität</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user