Skip to content

Commit

Permalink
Update to ExoPlayer 2.13.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin committed Mar 19, 2021
1 parent 8638169 commit 15aa3fc
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 70 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.12.3'
exoPlayerVersion = '2.13.2'
androidxLifecycleVersion = '2.2.0'
androidxRoomVersion = '2.3.0-alpha03'
groupieVersion = '2.8.1'
Expand Down
69 changes: 32 additions & 37 deletions app/src/main/java/org/schabi/newpipe/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,7 @@ private void initPlayer(final boolean playOnReady) {
simpleExoPlayer.addTextOutput(binding.subtitleView);

// Setup audio session with onboard equalizer
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
trackSelector.setParameters(trackSelector.buildUponParameters()
.setTunnelingAudioSessionId(C.generateAudioSessionIdV21(context)));
}
trackSelector.setParameters(trackSelector.buildUponParameters().setTunnelingEnabled(true));
}

private void initListeners() {
Expand Down Expand Up @@ -624,10 +621,10 @@ public void handleIntent(@NonNull final Intent intent) {
&& newQueue.getItem().getUrl().equals(playQueue.getItem().getUrl())
&& newQueue.getItem().getRecoveryPosition() != PlayQueueItem.RECOVERY_UNSET) {
// Player can have state = IDLE when playback is stopped or failed
// and we should retry() in this case
// and we should retry in this case
if (simpleExoPlayer.getPlaybackState()
== com.google.android.exoplayer2.Player.STATE_IDLE) {
simpleExoPlayer.retry();
simpleExoPlayer.prepare();
}
simpleExoPlayer.seekTo(playQueue.getIndex(), newQueue.getItem().getRecoveryPosition());
simpleExoPlayer.setPlayWhenReady(playWhenReady);
Expand All @@ -638,10 +635,10 @@ public void handleIntent(@NonNull final Intent intent) {
&& !playQueue.isDisposed()) {
// Do not re-init the same PlayQueue. Save time
// Player can have state = IDLE when playback is stopped or failed
// and we should retry() in this case
// and we should retry in this case
if (simpleExoPlayer.getPlaybackState()
== com.google.android.exoplayer2.Player.STATE_IDLE) {
simpleExoPlayer.retry();
simpleExoPlayer.prepare();
}
simpleExoPlayer.setPlayWhenReady(playWhenReady);

Expand Down Expand Up @@ -1653,7 +1650,7 @@ public void onStartTrackingTouch(final SeekBar seekBar) {

saveWasPlaying();
if (isPlaying()) {
simpleExoPlayer.setPlayWhenReady(false);
simpleExoPlayer.pause();
}

showControls(0);
Expand All @@ -1669,7 +1666,7 @@ public void onStopTrackingTouch(final SeekBar seekBar) {

seekTo(seekBar.getProgress());
if (wasPlaying || simpleExoPlayer.getDuration() == seekBar.getProgress()) {
simpleExoPlayer.setPlayWhenReady(true);
simpleExoPlayer.play();
}

binding.playbackCurrentTime.setText(getTimeString(seekBar.getProgress()));
Expand Down Expand Up @@ -1869,10 +1866,9 @@ private void hideSystemUIIfNeeded() {
//region

@Override // exoplayer listener
public void onPlayerStateChanged(final boolean playWhenReady, final int playbackState) {
public void onPlaybackStateChanged(final int playbackState) {
if (DEBUG) {
Log.d(TAG, "ExoPlayer - onPlayerStateChanged() called with: "
+ "playWhenReady = [" + playWhenReady + "], "
Log.d(TAG, "ExoPlayer - onPlaybackStateChanged() called with: "
+ "playbackState = [" + playbackState + "]");
}

Expand All @@ -1897,9 +1893,9 @@ public void onPlayerStateChanged(final boolean playWhenReady, final int playback
maybeCorrectSeekPosition();
if (!isPrepared) {
isPrepared = true;
onPrepared(playWhenReady);
onPrepared();
}
changeState(playWhenReady ? STATE_PLAYING : STATE_PAUSED);
changeState(simpleExoPlayer.getPlayWhenReady() ? STATE_PLAYING : STATE_PAUSED);
break;
case com.google.android.exoplayer2.Player.STATE_ENDED: // 4
changeState(STATE_COMPLETED);
Expand All @@ -1912,7 +1908,15 @@ public void onPlayerStateChanged(final boolean playWhenReady, final int playback
}

@Override // exoplayer listener
public void onLoadingChanged(final boolean isLoading) {
public void onPlayWhenReadyChanged(final boolean playWhenReady, final int reason) {
if (DEBUG) {
Log.d(TAG, "ExoPlayer - onPlayerStateChanged() called with: "
+ "playWhenReady = [" + playWhenReady + "]");
}
}

@Override // exoplayer listener
public void onIsLoadingChanged(final boolean isLoading) {
if (DEBUG) {
Log.d(TAG, "ExoPlayer - onLoadingChanged() called with: "
+ "isLoading = [" + isLoading + "]");
Expand Down Expand Up @@ -1956,7 +1960,8 @@ public void onPlaybackUnblock(final MediaSource mediaSource) {
if (currentState == STATE_BLOCKED) {
changeState(STATE_BUFFERING);
}
simpleExoPlayer.prepare(mediaSource);
simpleExoPlayer.setMediaSource(mediaSource);
simpleExoPlayer.prepare();
}

public void changeState(final int state) {
Expand Down Expand Up @@ -1987,16 +1992,12 @@ public void changeState(final int state) {
notifyPlaybackUpdateToListeners();
}

private void onPrepared(final boolean playWhenReady) {
if (DEBUG) {
Log.d(TAG, "onPrepared() called with: playWhenReady = [" + playWhenReady + "]");
}

private void onPrepared() {
binding.playbackSeekBar.setMax((int) simpleExoPlayer.getDuration());
binding.playbackEndTime.setText(getTimeString((int) simpleExoPlayer.getDuration()));
binding.playbackSpeed.setText(formatSpeed(getPlaybackSpeed()));

if (playWhenReady) {
if (simpleExoPlayer.getPlayWhenReady()) {
audioReactor.requestAudioFocus();
}
}
Expand Down Expand Up @@ -2355,6 +2356,12 @@ public void onPositionDiscontinuity(@DiscontinuityReason final int discontinuity
break;
}
case DISCONTINUITY_REASON_SEEK:
if (DEBUG) {
Log.d(TAG, "ExoPlayer - onSeekProcessed() called");
}
if (isPrepared) {
saveStreamProgressState();
}
case DISCONTINUITY_REASON_SEEK_ADJUSTMENT:
case DISCONTINUITY_REASON_INTERNAL:
if (playQueue.getIndex() != newWindowIndex) {
Expand Down Expand Up @@ -2419,10 +2426,8 @@ public void onPlayerError(@NonNull final ExoPlaybackException error) {
setRecovery();
reloadPlayQueueManager();
break;
case ExoPlaybackException.TYPE_OUT_OF_MEMORY:
case ExoPlaybackException.TYPE_REMOTE:
case ExoPlaybackException.TYPE_RENDERER:
case ExoPlaybackException.TYPE_TIMEOUT:
default:
showUnrecoverableError(error);
onPlaybackShutdown();
Expand Down Expand Up @@ -2627,16 +2632,6 @@ public void seekToDefault() {
simpleExoPlayer.seekToDefaultPosition();
}
}

@Override // exoplayer override
public void onSeekProcessed() {
if (DEBUG) {
Log.d(TAG, "ExoPlayer - onSeekProcessed() called");
}
if (isPrepared) {
saveStreamProgressState();
}
}
//endregion


Expand Down Expand Up @@ -2664,7 +2659,7 @@ public void play() {
}
}

simpleExoPlayer.setPlayWhenReady(true);
simpleExoPlayer.play();
saveStreamProgressState();
}

Expand All @@ -2677,7 +2672,7 @@ public void pause() {
}

audioReactor.abandonAudioFocus();
simpleExoPlayer.setPlayWhenReady(false);
simpleExoPlayer.pause();
saveStreamProgressState();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ private void onAudioFocusGain() {
animateAudio(DUCK_AUDIO_TO, 1.0f);

if (PlayerHelper.isResumeAfterAudioFocusGain(context)) {
player.setPlayWhenReady(true);
player.play();
}
}

private void onAudioFocusLoss() {
Log.d(TAG, "onAudioFocusLoss() called");
player.setPlayWhenReady(false);
player.pause();
}

private void onAudioFocusLossCanDuck() {
Expand Down Expand Up @@ -148,7 +148,7 @@ public void onAnimationEnd(final Animator animation) {
//////////////////////////////////////////////////////////////////////////*/

@Override
public void onAudioSessionId(final EventTime eventTime, final int audioSessionId) {
public void onAudioSessionIdChanged(final EventTime eventTime, final int audioSessionId) {
if (!PlayerHelper.isUsingDSP()) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.google.android.exoplayer2.LoadControl;
import com.google.android.exoplayer2.Renderer;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.trackselection.ExoTrackSelection;
import com.google.android.exoplayer2.upstream.Allocator;

public class LoadController implements LoadControl {
Expand Down Expand Up @@ -33,7 +33,7 @@ private LoadController(final int initialPlaybackBufferMs,
final DefaultLoadControl.Builder builder = new DefaultLoadControl.Builder();
builder.setBufferDurationsMs(minimumPlaybackBufferMs, optimalPlaybackBufferMs,
initialPlaybackBufferMs, initialPlaybackBufferMs);
internalLoadControl = builder.createDefaultLoadControl();
internalLoadControl = builder.build();
}

/*//////////////////////////////////////////////////////////////////////////
Expand All @@ -47,9 +47,9 @@ public void onPrepared() {
}

@Override
public void onTracksSelected(final Renderer[] renderers, final TrackGroupArray trackGroupArray,
final TrackSelectionArray trackSelectionArray) {
internalLoadControl.onTracksSelected(renderers, trackGroupArray, trackSelectionArray);
public void onTracksSelected(final Renderer[] renderers, final TrackGroupArray trackGroups,
final ExoTrackSelection[] trackSelections) {
internalLoadControl.onTracksSelected(renderers, trackGroups, trackSelections);
}

@Override
Expand Down Expand Up @@ -92,11 +92,12 @@ public boolean shouldContinueLoading(final long playbackPositionUs,

@Override
public boolean shouldStartPlayback(final long bufferedDurationUs, final float playbackSpeed,
final boolean rebuffering) {
final boolean rebuffering, final long targetLiveOffsetUs) {
final boolean isInitialPlaybackBufferFilled
= bufferedDurationUs >= this.initialPlaybackBufferUs * playbackSpeed;
final boolean isInternalStartingPlayback = internalLoadControl
.shouldStartPlayback(bufferedDurationUs, playbackSpeed, rebuffering);
.shouldStartPlayback(bufferedDurationUs, playbackSpeed, rebuffering,
targetLiveOffsetUs);
return isInitialPlaybackBufferFilled || isInternalStartingPlayback;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public MediaSessionManager(@NonNull final Context context,
@NonNull final Player player,
@NonNull final MediaSessionCallback callback) {
mediaSession = new MediaSessionCompat(context, TAG);
mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
| MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
mediaSession.setActive(true);

mediaSession.setPlaybackState(new PlaybackStateCompat.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import com.google.android.exoplayer2.SeekParameters;
import com.google.android.exoplayer2.text.CaptionStyleCompat;
import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;
import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.trackselection.ExoTrackSelection;
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout.ResizeMode;
import com.google.android.exoplayer2.util.MimeTypes;
Expand Down Expand Up @@ -323,7 +323,7 @@ public static int getPlaybackOptimalBufferMs() {
return 60000;
}

public static TrackSelection.Factory getQualitySelector() {
public static ExoTrackSelection.Factory getQualitySelector() {
return new AdaptiveTrackSelection.Factory(
1000,
AdaptiveTrackSelection.DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.trackselection.ExoTrackSelection;
import com.google.android.exoplayer2.util.Assertions;

/**
Expand All @@ -28,7 +28,7 @@ public class CustomTrackSelector extends DefaultTrackSelector {
private String preferredTextLanguage;

public CustomTrackSelector(final Context context,
final TrackSelection.Factory adaptiveTrackSelectionFactory) {
final ExoTrackSelection.Factory adaptiveTrackSelectionFactory) {
super(context, adaptiveTrackSelectionFactory);
}

Expand All @@ -50,7 +50,7 @@ public void setPreferredTextLanguage(@NonNull final String label) {

@Override
@Nullable
protected Pair<TrackSelection.Definition, TextTrackScore> selectTextTrack(
protected Pair<ExoTrackSelection.Definition, TextTrackScore> selectTextTrack(
final TrackGroupArray groups,
@NonNull final int[][] formatSupport,
@NonNull final Parameters params,
Expand Down Expand Up @@ -86,7 +86,7 @@ protected Pair<TrackSelection.Definition, TextTrackScore> selectTextTrack(
}
}
return selectedGroup == null ? null
: Pair.create(new TrackSelection.Definition(selectedGroup, selectedTrackIndex),
: Pair.create(new ExoTrackSelection.Definition(selectedGroup, selectedTrackIndex),
Assertions.checkNotNull(selectedTrackScore));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import androidx.annotation.Nullable;

import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.util.Util;

Expand Down Expand Up @@ -43,13 +44,13 @@ default MediaSource buildLiveMediaSource(@NonNull final PlayerDataSource dataSou
switch (type) {
case C.TYPE_SS:
return dataSource.getLiveSsMediaSourceFactory().setTag(metadata)
.createMediaSource(uri);
.createMediaSource(MediaItem.fromUri(uri));
case C.TYPE_DASH:
return dataSource.getLiveDashMediaSourceFactory().setTag(metadata)
.createMediaSource(uri);
.createMediaSource(MediaItem.fromUri(uri));
case C.TYPE_HLS:
return dataSource.getLiveHlsMediaSourceFactory().setTag(metadata)
.createMediaSource(uri);
.createMediaSource(MediaItem.fromUri(uri));
default:
throw new IllegalStateException("Unsupported type: " + type);
}
Expand All @@ -68,16 +69,16 @@ default MediaSource buildMediaSource(@NonNull final PlayerDataSource dataSource,
switch (type) {
case C.TYPE_SS:
return dataSource.getLiveSsMediaSourceFactory().setTag(metadata)
.createMediaSource(uri);
.createMediaSource(MediaItem.fromUri(uri));
case C.TYPE_DASH:
return dataSource.getDashMediaSourceFactory().setTag(metadata)
.createMediaSource(uri);
.createMediaSource(MediaItem.fromUri(uri));
case C.TYPE_HLS:
return dataSource.getHlsMediaSourceFactory().setTag(metadata)
.createMediaSource(uri);
.createMediaSource(MediaItem.fromUri(uri));
case C.TYPE_OTHER:
return dataSource.getExtractorMediaSourceFactory(cacheKey).setTag(metadata)
.createMediaSource(uri);
.createMediaSource(MediaItem.fromUri(uri));
default:
throw new IllegalStateException("Unsupported type: " + type);
}
Expand Down
Loading

0 comments on commit 15aa3fc

Please sign in to comment.