Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to ExoPlayer 2.11.4 #3513

Merged
merged 1 commit into from
May 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
10 changes: 0 additions & 10 deletions app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
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;
Expand Down Expand Up @@ -91,7 +90,6 @@ public final class BackgroundPlayer extends Service {
/*//////////////////////////////////////////////////////////////////////////
// Service-Activity Binder
//////////////////////////////////////////////////////////////////////////*/
private LockManager lockManager;
private SharedPreferences sharedPreferences;

/*//////////////////////////////////////////////////////////////////////////
Expand All @@ -116,7 +114,6 @@ public void onCreate() {
Log.d(TAG, "onCreate() called");
}
notificationManager = ((NotificationManager) getSystemService(NOTIFICATION_SERVICE));
lockManager = new LockManager(this);
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
assureCorrectAppLanguage(this);
ThemeHelper.setTheme(this);
Expand Down Expand Up @@ -166,9 +163,6 @@ private void onClose() {
Log.d(TAG, "onClose() called");
}

if (lockManager != null) {
lockManager.releaseWifiAndCpu();
}
if (basePlayerImpl != null) {
basePlayerImpl.savePlaybackState();
basePlayerImpl.stopActivityBinding();
Expand All @@ -179,7 +173,6 @@ private void onClose() {
}
mBinder = null;
basePlayerImpl = null;
lockManager = null;

stopForeground(true);
stopSelf();
Expand Down Expand Up @@ -663,7 +656,6 @@ public void onPlaying() {
resetNotification();
updateNotificationThumbnail();
updateNotification(R.drawable.ic_pause_white);
lockManager.acquireWifiAndCpu();
}

@Override
Expand All @@ -672,7 +664,6 @@ public void onPaused() {
resetNotification();
updateNotificationThumbnail();
updateNotification(R.drawable.ic_play_arrow_white);
lockManager.releaseWifiAndCpu();
}

@Override
Expand All @@ -687,7 +678,6 @@ public void onCompleted() {
}
updateNotificationThumbnail();
updateNotification(R.drawable.ic_replay_white);
lockManager.releaseWifiAndCpu();
}
}
}
16 changes: 9 additions & 7 deletions app/src/main/java/org/schabi/newpipe/player/BasePlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
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;
Expand Down Expand Up @@ -232,14 +232,18 @@ public void setup() {

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,
Expand Down Expand Up @@ -666,11 +670,9 @@ private Disposable getProgressReactor() {
//////////////////////////////////////////////////////////////////////////*/

@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 + "]");
}
Expand Down
11 changes: 0 additions & 11 deletions app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
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;
Expand Down Expand Up @@ -132,7 +131,6 @@ public final class PopupVideoPlayer extends Service {
private RemoteViews notRemoteView;

private VideoPlayerImpl playerImpl;
private LockManager lockManager;
private boolean isPopupClosing = false;

/*//////////////////////////////////////////////////////////////////////////
Expand All @@ -152,7 +150,6 @@ public void onCreate() {
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
notificationManager = ((NotificationManager) getSystemService(NOTIFICATION_SERVICE));

lockManager = new LockManager(this);
playerImpl = new VideoPlayerImpl(this);
ThemeHelper.setTheme(this);

Expand Down Expand Up @@ -378,9 +375,6 @@ public void closePopup() {
}

mBinder = null;
if (lockManager != null) {
lockManager.releaseWifiAndCpu();
}
if (notificationManager != null) {
notificationManager.cancel(NOTIFICATION_ID);
}
Expand Down Expand Up @@ -914,7 +908,6 @@ public void onPlaying() {
hideControls(DEFAULT_CONTROLS_DURATION, DEFAULT_CONTROLS_HIDE_TIME);

startForeground(NOTIFICATION_ID, notBuilder.build());
lockManager.acquireWifiAndCpu();
}

@Override
Expand All @@ -932,9 +925,7 @@ public void onPaused() {

resetNotification();
updateNotification(R.drawable.ic_play_arrow_white);

videoPlayPause.setBackgroundResource(R.drawable.ic_play_arrow_white);
lockManager.releaseWifiAndCpu();

stopForeground(false);
}
Expand All @@ -956,9 +947,7 @@ public void onCompleted() {

resetNotification();
updateNotification(R.drawable.ic_replay_white);

videoPlayPause.setBackgroundResource(R.drawable.ic_replay_white);
lockManager.releaseWifiAndCpu();

stopForeground(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,21 @@ private boolean isExpired() {
}

@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
public void maybeThrowSourceInfoRefreshError() throws IOException {
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) {
Expand All @@ -58,8 +63,13 @@ public void releasePeriod(final MediaPeriod mediaPeriod) {
}

@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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public int size() {
@Nullable
public ManagedMediaSource get(final int index) {
return (index < 0 || index >= size())
? null : (ManagedMediaSource) internalSource.getMediaSource(index);
? null : (ManagedMediaSource) internalSource.getMediaSource(index).getTag();
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

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;
Expand Down Expand Up @@ -48,27 +49,31 @@ public void setPreferredTextLanguage(@NonNull final String label) {
@Override
@Nullable
protected Pair<TrackSelection.Definition, TextTrackScore> 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;
Expand Down