From b4ddc8f96c6d021f155101b5c058c0459a281733 Mon Sep 17 00:00:00 2001 From: Stypox Date: Fri, 1 May 2020 11:58:24 +0200 Subject: [PATCH] Update to ExoPlayer 2.11.4 --- app/build.gradle | 2 +- .../newpipe/player/BackgroundPlayer.java | 10 ---------- .../org/schabi/newpipe/player/BasePlayer.java | 16 +++++++++------- .../newpipe/player/PopupVideoPlayer.java | 11 ----------- .../player/mediasource/LoadedMediaSource.java | 18 ++++++++++++++---- .../player/mediasource/ManagedMediaSource.java | 7 +++++++ .../ManagedMediaSourcePlaylist.java | 2 +- .../player/playback/CustomTrackSelector.java | 15 ++++++++++----- 8 files changed, 42 insertions(+), 39 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index b99e89271..9e823a503 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -80,7 +80,7 @@ android { ext { androidxLibVersion = '1.0.0' - exoPlayerLibVersion = '2.10.8' + exoPlayerLibVersion = '2.11.4' roomDbLibVersion = '2.1.0' leakCanaryLibVersion = '1.5.4' //1.6.1 okHttpLibVersion = '3.12.6' diff --git a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java index 72cc75a66..631942e6e 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java @@ -49,7 +49,6 @@ import org.schabi.newpipe.BuildConfig; import org.schabi.newpipe.R; import org.schabi.newpipe.extractor.stream.StreamInfo; import org.schabi.newpipe.player.event.PlayerEventListener; -import org.schabi.newpipe.player.helper.LockManager; import org.schabi.newpipe.player.playqueue.PlayQueueItem; import org.schabi.newpipe.player.resolver.AudioPlaybackResolver; import org.schabi.newpipe.player.resolver.MediaSourceTag; @@ -91,7 +90,6 @@ public final class BackgroundPlayer extends Service { /*////////////////////////////////////////////////////////////////////////// // Service-Activity Binder //////////////////////////////////////////////////////////////////////////*/ - private LockManager lockManager; private SharedPreferences sharedPreferences; /*////////////////////////////////////////////////////////////////////////// @@ -116,7 +114,6 @@ public final class BackgroundPlayer extends Service { Log.d(TAG, "onCreate() called"); } notificationManager = ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)); - lockManager = new LockManager(this); sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); assureCorrectAppLanguage(this); ThemeHelper.setTheme(this); @@ -166,9 +163,6 @@ public final class BackgroundPlayer extends Service { Log.d(TAG, "onClose() called"); } - if (lockManager != null) { - lockManager.releaseWifiAndCpu(); - } if (basePlayerImpl != null) { basePlayerImpl.savePlaybackState(); basePlayerImpl.stopActivityBinding(); @@ -179,7 +173,6 @@ public final class BackgroundPlayer extends Service { } mBinder = null; basePlayerImpl = null; - lockManager = null; stopForeground(true); stopSelf(); @@ -663,7 +656,6 @@ public final class BackgroundPlayer extends Service { resetNotification(); updateNotificationThumbnail(); updateNotification(R.drawable.ic_pause_white); - lockManager.acquireWifiAndCpu(); } @Override @@ -672,7 +664,6 @@ public final class BackgroundPlayer extends Service { resetNotification(); updateNotificationThumbnail(); updateNotification(R.drawable.ic_play_arrow_white); - lockManager.releaseWifiAndCpu(); } @Override @@ -687,7 +678,6 @@ public final class BackgroundPlayer extends Service { } updateNotificationThumbnail(); updateNotification(R.drawable.ic_replay_white); - lockManager.releaseWifiAndCpu(); } } } diff --git a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java index 1b8d0ccf6..f5a669788 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java @@ -35,9 +35,9 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.DefaultRenderersFactory; import com.google.android.exoplayer2.ExoPlaybackException; -import com.google.android.exoplayer2.ExoPlayerFactory; import com.google.android.exoplayer2.LoadControl; import com.google.android.exoplayer2.PlaybackParameters; import com.google.android.exoplayer2.Player; @@ -232,14 +232,18 @@ public abstract class BasePlayer implements public void initPlayer(final boolean playOnReady) { if (DEBUG) { - Log.d(TAG, "initPlayer() called with: context = [" + context + "]"); + Log.d(TAG, "initPlayer() called with: playOnReady = [" + playOnReady + "]"); } - simpleExoPlayer = ExoPlayerFactory - .newSimpleInstance(context, renderFactory, trackSelector, loadControl); + simpleExoPlayer = new SimpleExoPlayer.Builder(context, renderFactory) + .setTrackSelector(trackSelector) + .setLoadControl(loadControl) + .build(); simpleExoPlayer.addListener(this); simpleExoPlayer.setPlayWhenReady(playOnReady); simpleExoPlayer.setSeekParameters(PlayerHelper.getSeekParameters(context)); + simpleExoPlayer.setWakeMode(C.WAKE_MODE_NETWORK); + simpleExoPlayer.setHandleAudioBecomingNoisy(true); audioReactor = new AudioReactor(context, simpleExoPlayer); mediaSessionManager = new MediaSessionManager(context, simpleExoPlayer, @@ -666,11 +670,9 @@ public abstract class BasePlayer implements //////////////////////////////////////////////////////////////////////////*/ @Override - public void onTimelineChanged(final Timeline timeline, final Object manifest, - @Player.TimelineChangeReason final int reason) { + public void onTimelineChanged(final Timeline timeline, final int reason) { if (DEBUG) { Log.d(TAG, "ExoPlayer - onTimelineChanged() called with " - + (manifest == null ? "no manifest" : "available manifest") + ", " + "timeline size = [" + timeline.getWindowCount() + "], " + "reason = [" + reason + "]"); } diff --git a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java index de9e9b746..b00a213bf 100644 --- a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java @@ -68,7 +68,6 @@ import org.schabi.newpipe.BuildConfig; import org.schabi.newpipe.R; import org.schabi.newpipe.extractor.stream.VideoStream; import org.schabi.newpipe.player.event.PlayerEventListener; -import org.schabi.newpipe.player.helper.LockManager; import org.schabi.newpipe.player.helper.PlayerHelper; import org.schabi.newpipe.player.resolver.MediaSourceTag; import org.schabi.newpipe.player.resolver.VideoPlaybackResolver; @@ -132,7 +131,6 @@ public final class PopupVideoPlayer extends Service { private RemoteViews notRemoteView; private VideoPlayerImpl playerImpl; - private LockManager lockManager; private boolean isPopupClosing = false; /*////////////////////////////////////////////////////////////////////////// @@ -152,7 +150,6 @@ public final class PopupVideoPlayer extends Service { windowManager = (WindowManager) getSystemService(WINDOW_SERVICE); notificationManager = ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)); - lockManager = new LockManager(this); playerImpl = new VideoPlayerImpl(this); ThemeHelper.setTheme(this); @@ -378,9 +375,6 @@ public final class PopupVideoPlayer extends Service { } mBinder = null; - if (lockManager != null) { - lockManager.releaseWifiAndCpu(); - } if (notificationManager != null) { notificationManager.cancel(NOTIFICATION_ID); } @@ -914,7 +908,6 @@ public final class PopupVideoPlayer extends Service { hideControls(DEFAULT_CONTROLS_DURATION, DEFAULT_CONTROLS_HIDE_TIME); startForeground(NOTIFICATION_ID, notBuilder.build()); - lockManager.acquireWifiAndCpu(); } @Override @@ -932,9 +925,7 @@ public final class PopupVideoPlayer extends Service { resetNotification(); updateNotification(R.drawable.ic_play_arrow_white); - videoPlayPause.setBackgroundResource(R.drawable.ic_play_arrow_white); - lockManager.releaseWifiAndCpu(); stopForeground(false); } @@ -956,9 +947,7 @@ public final class PopupVideoPlayer extends Service { resetNotification(); updateNotification(R.drawable.ic_replay_white); - videoPlayPause.setBackgroundResource(R.drawable.ic_replay_white); - lockManager.releaseWifiAndCpu(); stopForeground(false); } diff --git a/app/src/main/java/org/schabi/newpipe/player/mediasource/LoadedMediaSource.java b/app/src/main/java/org/schabi/newpipe/player/mediasource/LoadedMediaSource.java index a4a6eb2ce..cdbf8609b 100644 --- a/app/src/main/java/org/schabi/newpipe/player/mediasource/LoadedMediaSource.java +++ b/app/src/main/java/org/schabi/newpipe/player/mediasource/LoadedMediaSource.java @@ -36,9 +36,9 @@ public class LoadedMediaSource implements ManagedMediaSource { } @Override - public void prepareSource(final SourceInfoRefreshListener listener, + public void prepareSource(final MediaSourceCaller mediaSourceCaller, @Nullable final TransferListener mediaTransferListener) { - source.prepareSource(listener, mediaTransferListener); + source.prepareSource(mediaSourceCaller, mediaTransferListener); } @Override @@ -46,6 +46,11 @@ public class LoadedMediaSource implements ManagedMediaSource { source.maybeThrowSourceInfoRefreshError(); } + @Override + public void enable(final MediaSourceCaller caller) { + source.enable(caller); + } + @Override public MediaPeriod createPeriod(final MediaPeriodId id, final Allocator allocator, final long startPositionUs) { @@ -58,8 +63,13 @@ public class LoadedMediaSource implements ManagedMediaSource { } @Override - public void releaseSource(final SourceInfoRefreshListener listener) { - source.releaseSource(listener); + public void disable(final MediaSourceCaller caller) { + source.disable(caller); + } + + @Override + public void releaseSource(final MediaSourceCaller mediaSourceCaller) { + source.releaseSource(mediaSourceCaller); } @Override diff --git a/app/src/main/java/org/schabi/newpipe/player/mediasource/ManagedMediaSource.java b/app/src/main/java/org/schabi/newpipe/player/mediasource/ManagedMediaSource.java index 9d6b94893..21fddbe86 100644 --- a/app/src/main/java/org/schabi/newpipe/player/mediasource/ManagedMediaSource.java +++ b/app/src/main/java/org/schabi/newpipe/player/mediasource/ManagedMediaSource.java @@ -1,6 +1,7 @@ package org.schabi.newpipe.player.mediasource; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.google.android.exoplayer2.source.MediaSource; @@ -27,4 +28,10 @@ public interface ManagedMediaSource extends MediaSource { * @return whether this source is for the specified stream */ boolean isStreamEqual(@NonNull PlayQueueItem stream); + + @Nullable + @Override + default Object getTag() { + return this; + } } diff --git a/app/src/main/java/org/schabi/newpipe/player/mediasource/ManagedMediaSourcePlaylist.java b/app/src/main/java/org/schabi/newpipe/player/mediasource/ManagedMediaSourcePlaylist.java index 582eb31ca..ff0cf21fa 100644 --- a/app/src/main/java/org/schabi/newpipe/player/mediasource/ManagedMediaSourcePlaylist.java +++ b/app/src/main/java/org/schabi/newpipe/player/mediasource/ManagedMediaSourcePlaylist.java @@ -35,7 +35,7 @@ public class ManagedMediaSourcePlaylist { @Nullable public ManagedMediaSource get(final int index) { return (index < 0 || index >= size()) - ? null : (ManagedMediaSource) internalSource.getMediaSource(index); + ? null : (ManagedMediaSource) internalSource.getMediaSource(index).getTag(); } @NonNull diff --git a/app/src/main/java/org/schabi/newpipe/player/playback/CustomTrackSelector.java b/app/src/main/java/org/schabi/newpipe/player/playback/CustomTrackSelector.java index 0c4e7b2d0..2ba05b443 100644 --- a/app/src/main/java/org/schabi/newpipe/player/playback/CustomTrackSelector.java +++ b/app/src/main/java/org/schabi/newpipe/player/playback/CustomTrackSelector.java @@ -8,6 +8,7 @@ import androidx.annotation.Nullable; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.Format; +import com.google.android.exoplayer2.RendererCapabilities.Capabilities; import com.google.android.exoplayer2.source.TrackGroup; import com.google.android.exoplayer2.source.TrackGroupArray; import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; @@ -48,27 +49,31 @@ public class CustomTrackSelector extends DefaultTrackSelector { @Override @Nullable protected Pair selectTextTrack( - final TrackGroupArray groups, final int[][] formatSupport, final Parameters params, + final TrackGroupArray groups, + @NonNull final int[][] formatSupport, + @NonNull final Parameters params, @Nullable final String selectedAudioLanguage) { TrackGroup selectedGroup = null; int selectedTrackIndex = C.INDEX_UNSET; - int newPipeTrackScore = 0; TextTrackScore selectedTrackScore = null; + for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) { TrackGroup trackGroup = groups.get(groupIndex); - int[] trackFormatSupport = formatSupport[groupIndex]; + @Capabilities int[] trackFormatSupport = formatSupport[groupIndex]; + for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) { if (isSupported(trackFormatSupport[trackIndex], params.exceedRendererCapabilitiesIfNecessary)) { Format format = trackGroup.getFormat(trackIndex); TextTrackScore trackScore = new TextTrackScore(format, params, trackFormatSupport[trackIndex], selectedAudioLanguage); + if (formatHasLanguage(format, preferredTextLanguage)) { selectedGroup = trackGroup; selectedTrackIndex = trackIndex; selectedTrackScore = trackScore; - // found user selected match (perfect!) - break; + break; // found user selected match (perfect!) + } else if (trackScore.isWithinConstraints && (selectedTrackScore == null || trackScore.compareTo(selectedTrackScore) > 0)) { selectedGroup = trackGroup;