Update to ExoPlayer 2.10.5

This commit is contained in:
Robin 2019-10-07 07:54:31 +02:00 committed by TobiGr
parent a02e12abe8
commit dcd5197a19
7 changed files with 57 additions and 82 deletions

View file

@ -44,7 +44,7 @@ android {
ext { ext {
androidxLibVersion = '1.0.0' androidxLibVersion = '1.0.0'
exoPlayerLibVersion = '2.9.6' //2.10.5 exoPlayerLibVersion = '2.10.5'
roomDbLibVersion = '2.1.0' roomDbLibVersion = '2.1.0'
leakCanaryLibVersion = '1.5.4' //1.6.1 leakCanaryLibVersion = '1.5.4' //1.6.1
okHttpLibVersion = '3.12.1' okHttpLibVersion = '3.12.1'

View file

@ -2,11 +2,12 @@ package org.schabi.newpipe.player.helper;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.support.v4.media.session.MediaSessionCompat;
import android.view.KeyEvent;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.media.session.MediaButtonReceiver; import androidx.media.session.MediaButtonReceiver;
import android.support.v4.media.session.MediaSessionCompat;
import android.view.KeyEvent;
import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector; import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector;
@ -27,10 +28,10 @@ public class MediaSessionManager {
this.mediaSession = new MediaSessionCompat(context, TAG); this.mediaSession = new MediaSessionCompat(context, TAG);
this.mediaSession.setActive(true); this.mediaSession.setActive(true);
this.sessionConnector = new MediaSessionConnector(mediaSession, this.sessionConnector = new MediaSessionConnector(mediaSession);
new PlayQueuePlaybackController(callback)); this.sessionConnector.setControlDispatcher(new PlayQueuePlaybackController(callback));
this.sessionConnector.setQueueNavigator(new PlayQueueNavigator(mediaSession, callback)); this.sessionConnector.setQueueNavigator(new PlayQueueNavigator(mediaSession, callback));
this.sessionConnector.setPlayer(player, null); this.sessionConnector.setPlayer(player);
} }
@Nullable @Nullable
@ -43,7 +44,7 @@ public class MediaSessionManager {
* Should be called on player destruction to prevent leakage. * Should be called on player destruction to prevent leakage.
* */ * */
public void dispose() { public void dispose() {
this.sessionConnector.setPlayer(null, null); this.sessionConnector.setPlayer(null);
this.sessionConnector.setQueueNavigator(null); this.sessionConnector.setQueueNavigator(null);
this.mediaSession.setActive(false); this.mediaSession.setActive(false);
this.mediaSession.release(); this.mediaSession.release();

View file

@ -2,10 +2,12 @@ package org.schabi.newpipe.player.mediasession;
import android.os.Bundle; import android.os.Bundle;
import android.os.ResultReceiver; import android.os.ResultReceiver;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.support.v4.media.session.MediaSessionCompat; import android.support.v4.media.session.MediaSessionCompat;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.ControlDispatcher;
import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector; import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
@ -63,17 +65,17 @@ public class PlayQueueNavigator implements MediaSessionConnector.QueueNavigator
} }
@Override @Override
public void onSkipToPrevious(Player player) { public void onSkipToPrevious(Player player, ControlDispatcher controlDispatcher) {
callback.onSkipToPrevious(); callback.onSkipToPrevious();
} }
@Override @Override
public void onSkipToQueueItem(Player player, long id) { public void onSkipToQueueItem(Player player, ControlDispatcher controlDispatcher, long id) {
callback.onSkipToIndex((int) id); callback.onSkipToIndex((int) id);
} }
@Override @Override
public void onSkipToNext(Player player) { public void onSkipToNext(Player player, ControlDispatcher controlDispatcher) {
callback.onSkipToNext(); callback.onSkipToNext();
} }
@ -100,12 +102,7 @@ public class PlayQueueNavigator implements MediaSessionConnector.QueueNavigator
} }
@Override @Override
public String[] getCommands() { public boolean onCommand(Player player, ControlDispatcher controlDispatcher, String command, Bundle extras, ResultReceiver cb) {
return new String[0]; return false;
}
@Override
public void onCommand(Player player, String command, Bundle extras, ResultReceiver cb) {
} }
} }

View file

@ -1,9 +1,9 @@
package org.schabi.newpipe.player.mediasession; package org.schabi.newpipe.player.mediasession;
import com.google.android.exoplayer2.DefaultControlDispatcher;
import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.ext.mediasession.DefaultPlaybackController;
public class PlayQueuePlaybackController extends DefaultPlaybackController { public class PlayQueuePlaybackController extends DefaultControlDispatcher {
private final MediaSessionCallback callback; private final MediaSessionCallback callback;
public PlayQueuePlaybackController(final MediaSessionCallback callback) { public PlayQueuePlaybackController(final MediaSessionCallback callback) {
@ -12,12 +12,12 @@ public class PlayQueuePlaybackController extends DefaultPlaybackController {
} }
@Override @Override
public void onPlay(Player player) { public boolean dispatchSetPlayWhenReady(Player player, boolean playWhenReady) {
callback.onPlay(); if(playWhenReady) {
} callback.onPlay();
} else {
@Override callback.onPause();
public void onPause(Player player) { }
callback.onPause(); return true;
} }
} }

View file

@ -1,15 +1,17 @@
package org.schabi.newpipe.player.playback; package org.schabi.newpipe.player.playback;
import androidx.annotation.NonNull;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Pair; import android.util.Pair;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
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;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.trackselection.FixedTrackSelection;
import com.google.android.exoplayer2.trackselection.TrackSelection; import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
@ -21,7 +23,6 @@ import com.google.android.exoplayer2.util.Assertions;
* a broader set of languages. * a broader set of languages.
* */ * */
public class CustomTrackSelector extends DefaultTrackSelector { public class CustomTrackSelector extends DefaultTrackSelector {
private static final int WITHIN_RENDERER_CAPABILITIES_BONUS = 1000;
private String preferredTextLanguage; private String preferredTextLanguage;
@ -41,23 +42,22 @@ public class CustomTrackSelector extends DefaultTrackSelector {
} }
} }
/** @see DefaultTrackSelector#formatHasLanguage(Format, String)*/ private static boolean formatHasLanguage(Format format, String language) {
protected static boolean formatHasLanguage(Format format, String language) {
return language != null && TextUtils.equals(language, format.language); return language != null && TextUtils.equals(language, format.language);
} }
/** @see DefaultTrackSelector#formatHasNoLanguage(Format)*/
protected static boolean formatHasNoLanguage(Format format) {
return TextUtils.isEmpty(format.language) || formatHasLanguage(format, C.LANGUAGE_UNDETERMINED);
}
/** @see DefaultTrackSelector#selectTextTrack(TrackGroupArray, int[][], Parameters) */
@Override @Override
protected Pair<TrackSelection, Integer> selectTextTrack(TrackGroupArray groups, int[][] formatSupport, @Nullable
Parameters params) { protected Pair<TrackSelection.Definition, TextTrackScore> selectTextTrack(
TrackGroupArray groups,
int[][] formatSupport,
Parameters params,
@Nullable String selectedAudioLanguage)
throws ExoPlaybackException {
TrackGroup selectedGroup = null; TrackGroup selectedGroup = null;
int selectedTrackIndex = 0; int selectedTrackIndex = C.INDEX_UNSET;
int selectedTrackScore = 0; int newPipeTrackScore = 0;
TextTrackScore selectedTrackScore = null;
for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) { for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
TrackGroup trackGroup = groups.get(groupIndex); TrackGroup trackGroup = groups.get(groupIndex);
int[] trackFormatSupport = formatSupport[groupIndex]; int[] trackFormatSupport = formatSupport[groupIndex];
@ -65,41 +65,17 @@ public class CustomTrackSelector extends DefaultTrackSelector {
if (isSupported(trackFormatSupport[trackIndex], if (isSupported(trackFormatSupport[trackIndex],
params.exceedRendererCapabilitiesIfNecessary)) { params.exceedRendererCapabilitiesIfNecessary)) {
Format format = trackGroup.getFormat(trackIndex); Format format = trackGroup.getFormat(trackIndex);
int maskedSelectionFlags = TextTrackScore trackScore =
format.selectionFlags & ~params.disabledTextTrackSelectionFlags; new TextTrackScore(
boolean isDefault = (maskedSelectionFlags & C.SELECTION_FLAG_DEFAULT) != 0; format, params, trackFormatSupport[trackIndex], selectedAudioLanguage);
boolean isForced = (maskedSelectionFlags & C.SELECTION_FLAG_FORCED) != 0; if(formatHasLanguage(format, preferredTextLanguage)) {
int trackScore; selectedGroup = trackGroup;
boolean preferredLanguageFound = formatHasLanguage(format, preferredTextLanguage); selectedTrackIndex = trackIndex;
if (preferredLanguageFound selectedTrackScore = trackScore;
|| (params.selectUndeterminedTextLanguage && formatHasNoLanguage(format))) { // found user selected match (perfect!)
if (isDefault) { break;
trackScore = 8; } else if (trackScore.isWithinConstraints
} else if (!isForced) { && (selectedTrackScore == null || trackScore.compareTo(selectedTrackScore) > 0)) {
// Prefer non-forced to forced if a preferred text language has been specified. Where
// both are provided the non-forced track will usually contain the forced subtitles as
// a subset.
trackScore = 6;
} else {
trackScore = 4;
}
trackScore += preferredLanguageFound ? 1 : 0;
} else if (isDefault) {
trackScore = 3;
} else if (isForced) {
if (formatHasLanguage(format, params.preferredAudioLanguage)) {
trackScore = 2;
} else {
trackScore = 1;
}
} else {
// Track should not be selected.
continue;
}
if (isSupported(trackFormatSupport[trackIndex], false)) {
trackScore += WITHIN_RENDERER_CAPABILITIES_BONUS;
}
if (trackScore > selectedTrackScore) {
selectedGroup = trackGroup; selectedGroup = trackGroup;
selectedTrackIndex = trackIndex; selectedTrackIndex = trackIndex;
selectedTrackScore = trackScore; selectedTrackScore = trackScore;
@ -110,6 +86,7 @@ public class CustomTrackSelector extends DefaultTrackSelector {
return selectedGroup == null return selectedGroup == null
? null ? null
: Pair.create( : Pair.create(
new FixedTrackSelection(selectedGroup, selectedTrackIndex), selectedTrackScore); new TrackSelection.Definition(selectedGroup, selectedTrackIndex),
Assertions.checkNotNull(selectedTrackScore));
} }
} }

View file

@ -6,7 +6,7 @@ buildscript {
google() google()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.2.0' classpath 'com.android.tools.build:gradle:3.4.0'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files

View file

@ -1,6 +1,6 @@
#Sun Sep 22 10:40:45 CEST 2019 #Mon Oct 07 06:29:33 CEST 2019
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip