From eba0b07782b2520c4aadd2e9df4f2f86528d6834 Mon Sep 17 00:00:00 2001 From: Robin Date: Tue, 19 Jan 2021 09:27:29 +0100 Subject: [PATCH] Update to ExoPlayer 2.12.3 --- app/build.gradle | 2 +- .../org/schabi/newpipe/player/Player.java | 9 +++-- .../newpipe/player/helper/LoadController.java | 7 ++-- .../newpipe/player/helper/PlayerHelper.java | 4 +-- .../player/mediasource/FailedMediaSource.java | 9 +++++ .../player/mediasource/LoadedMediaSource.java | 34 +++++++++++++++++++ .../mediasource/PlaceholderMediaSource.java | 9 +++++ 7 files changed, 64 insertions(+), 10 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 486502cd8..37eca2ed5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -96,7 +96,7 @@ ext { checkstyleVersion = '8.38' stethoVersion = '1.5.1' leakCanaryVersion = '2.5' - exoPlayerVersion = '2.11.8' + exoPlayerVersion = '2.12.3' androidxLifecycleVersion = '2.2.0' androidxRoomVersion = '2.3.0-alpha03' groupieVersion = '2.8.1' diff --git a/app/src/main/java/org/schabi/newpipe/player/Player.java b/app/src/main/java/org/schabi/newpipe/player/Player.java index ba8e856df..535a5033a 100644 --- a/app/src/main/java/org/schabi/newpipe/player/Player.java +++ b/app/src/main/java/org/schabi/newpipe/player/Player.java @@ -601,7 +601,8 @@ public final class Player implements final PlaybackParameters savedParameters = retrievePlaybackParametersFromPrefs(this); final float playbackSpeed = savedParameters.speed; final float playbackPitch = savedParameters.pitch; - final boolean playbackSkipSilence = savedParameters.skipSilence; + final boolean playbackSkipSilence = getPrefs().getBoolean(getContext().getString( + R.string.playback_skip_silence_key), getPlaybackSkipSilence()); final boolean samePlayQueue = playQueue != null && playQueue.equals(newQueue); final int repeatMode = intent.getIntExtra(REPEAT_MODE, getRepeatMode()); @@ -1432,7 +1433,8 @@ public final class Player implements } public boolean getPlaybackSkipSilence() { - return getPlaybackParameters().skipSilence; + return simpleExoPlayer != null + && simpleExoPlayer.getAudioComponent().getSkipSilenceEnabled(); } public PlaybackParameters getPlaybackParameters() { @@ -1457,7 +1459,8 @@ public final class Player implements savePlaybackParametersToPrefs(this, roundedSpeed, roundedPitch, skipSilence); simpleExoPlayer.setPlaybackParameters( - new PlaybackParameters(roundedSpeed, roundedPitch, skipSilence)); + new PlaybackParameters(roundedSpeed, roundedPitch)); + simpleExoPlayer.getAudioComponent().setSkipSilenceEnabled(skipSilence); } //endregion diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/LoadController.java b/app/src/main/java/org/schabi/newpipe/player/helper/LoadController.java index 0604e6ae8..162872267 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/LoadController.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/LoadController.java @@ -80,12 +80,13 @@ public class LoadController implements LoadControl { } @Override - public boolean shouldContinueLoading(final long bufferedDurationUs, - final float playbackSpeed) { + public boolean shouldContinueLoading(final long playbackPositionUs, + final long bufferedDurationUs, final float playbackSpeed) { if (!preloadingEnabled) { return false; } - return internalLoadControl.shouldContinueLoading(bufferedDurationUs, playbackSpeed); + return internalLoadControl.shouldContinueLoading(playbackPositionUs, bufferedDurationUs, + playbackSpeed); } @Override diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java index ccc73e81f..f653531eb 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java @@ -494,9 +494,7 @@ public final class PlayerHelper { R.string.playback_speed_key), player.getPlaybackSpeed()); final float pitch = player.getPrefs().getFloat(player.getContext().getString( R.string.playback_pitch_key), player.getPlaybackPitch()); - final boolean skipSilence = player.getPrefs().getBoolean(player.getContext().getString( - R.string.playback_skip_silence_key), player.getPlaybackSkipSilence()); - return new PlaybackParameters(speed, pitch, skipSilence); + return new PlaybackParameters(speed, pitch); } public static void savePlaybackParametersToPrefs(final Player player, diff --git a/app/src/main/java/org/schabi/newpipe/player/mediasource/FailedMediaSource.java b/app/src/main/java/org/schabi/newpipe/player/mediasource/FailedMediaSource.java index c09a44c08..7594f3a16 100644 --- a/app/src/main/java/org/schabi/newpipe/player/mediasource/FailedMediaSource.java +++ b/app/src/main/java/org/schabi/newpipe/player/mediasource/FailedMediaSource.java @@ -5,6 +5,7 @@ import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.google.android.exoplayer2.MediaItem; import com.google.android.exoplayer2.source.BaseMediaSource; import com.google.android.exoplayer2.source.MediaPeriod; import com.google.android.exoplayer2.upstream.Allocator; @@ -54,6 +55,14 @@ public class FailedMediaSource extends BaseMediaSource implements ManagedMediaSo return System.currentTimeMillis() >= retryTimestamp; } + /** + * Returns the {@link MediaItem} whose media is provided by the source. + */ + @Override + public MediaItem getMediaItem() { + return MediaItem.fromUri(playQueueItem.getUrl()); + } + @Override public void maybeThrowSourceInfoRefreshError() throws IOException { throw new IOException(error); 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 cdbf8609b..746a97581 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 @@ -5,6 +5,8 @@ import android.os.Handler; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.google.android.exoplayer2.MediaItem; +import com.google.android.exoplayer2.drm.DrmSessionEventListener; import com.google.android.exoplayer2.source.MediaPeriod; import com.google.android.exoplayer2.source.MediaSource; import com.google.android.exoplayer2.source.MediaSourceEventListener; @@ -83,6 +85,38 @@ public class LoadedMediaSource implements ManagedMediaSource { source.removeEventListener(eventListener); } + /** + * Adds a {@link DrmSessionEventListener} to the list of listeners which are notified of DRM + * events for this media source. + * + * @param handler A handler on the which listener events will be posted. + * @param eventListener The listener to be added. + */ + @Override + public void addDrmEventListener(final Handler handler, + final DrmSessionEventListener eventListener) { + source.addDrmEventListener(handler, eventListener); + } + + /** + * Removes a {@link DrmSessionEventListener} from the list of listeners which are notified of + * DRM events for this media source. + * + * @param eventListener The listener to be removed. + */ + @Override + public void removeDrmEventListener(final DrmSessionEventListener eventListener) { + source.removeDrmEventListener(eventListener); + } + + /** + * Returns the {@link MediaItem} whose media is provided by the source. + */ + @Override + public MediaItem getMediaItem() { + return source.getMediaItem(); + } + @Override public boolean shouldBeReplacedWith(@NonNull final PlayQueueItem newIdentity, final boolean isInterruptable) { diff --git a/app/src/main/java/org/schabi/newpipe/player/mediasource/PlaceholderMediaSource.java b/app/src/main/java/org/schabi/newpipe/player/mediasource/PlaceholderMediaSource.java index f73a219d7..1cd855627 100644 --- a/app/src/main/java/org/schabi/newpipe/player/mediasource/PlaceholderMediaSource.java +++ b/app/src/main/java/org/schabi/newpipe/player/mediasource/PlaceholderMediaSource.java @@ -3,6 +3,7 @@ package org.schabi.newpipe.player.mediasource; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.google.android.exoplayer2.MediaItem; import com.google.android.exoplayer2.source.BaseMediaSource; import com.google.android.exoplayer2.source.MediaPeriod; import com.google.android.exoplayer2.upstream.Allocator; @@ -11,6 +12,14 @@ import com.google.android.exoplayer2.upstream.TransferListener; import org.schabi.newpipe.player.playqueue.PlayQueueItem; public class PlaceholderMediaSource extends BaseMediaSource implements ManagedMediaSource { + /** + * Returns the {@link MediaItem} whose media is provided by the source. + */ + @Override + public MediaItem getMediaItem() { + return null; + } + // Do nothing, so this will stall the playback @Override public void maybeThrowSourceInfoRefreshError() { }