Skip to content

Commit

Permalink
Update to ExoPlayer 2.12.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin committed Jan 19, 2021
1 parent 9a65f02 commit febf668
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
9 changes: 6 additions & 3 deletions app/src/main/java/org/schabi/newpipe/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -1433,7 +1434,8 @@ public float getPlaybackPitch() {
}

public boolean getPlaybackSkipSilence() {
return getPlaybackParameters().skipSilence;
return simpleExoPlayer != null
&& simpleExoPlayer.getAudioComponent().getSkipSilenceEnabled();
}

public PlaybackParameters getPlaybackParameters() {
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -83,6 +85,38 @@ 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() { }
Expand Down

0 comments on commit febf668

Please sign in to comment.