From 674e3b4408b4a0f28d15fddeef2787d484a24509 Mon Sep 17 00:00:00 2001 From: Robin Date: Tue, 19 Jan 2021 09:16:00 +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 | 33 +++++++++++++++++++ .../mediasource/PlaceholderMediaSource.java | 9 +++++ 7 files changed, 63 insertions(+), 10 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 486502cd868..37eca2ed5cf 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 13a0a7d0211..90025cbc79d 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 void handleIntent(@NonNull final Intent intent) { 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()); @@ -1433,7 +1434,8 @@ public float getPlaybackPitch() { } public boolean getPlaybackSkipSilence() { - return getPlaybackParameters().skipSilence; + return simpleExoPlayer != null && + simpleExoPlayer.getAudioComponent().getSkipSilenceEnabled(); } public PlaybackParameters getPlaybackParameters() { @@ -1458,7 +1460,8 @@ public void setPlaybackParameters(final float speed, final float pitch, 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 0604e6ae83c..162872267a6 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 boolean retainBackBufferFromKeyframe() { } @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 54021b6169b..3e25a40a0ec 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 @@ -511,9 +511,7 @@ public static PlaybackParameters retrievePlaybackParametersFromPrefs(final Playe 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 c09a44c08e5..7594f3a1600 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 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 @@ private boolean canRetry() { 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 cdbf8609b2b..58c4c3ea290 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 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,37 @@ public void removeEventListener(final MediaSourceEventListener eventListener) { 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 f73a219d7e4..1cd8556270b 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 @@ 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 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() { }