From 052c9a9869b97d3050c1f7c2166bba67575195e0 Mon Sep 17 00:00:00 2001 From: John Zhen Mo Date: Tue, 24 Oct 2017 22:18:44 -0700 Subject: [PATCH] -Added persisting settings when switching between players. --- .../newpipe/player/BackgroundPlayer.java | 4 ++-- .../org/schabi/newpipe/player/BasePlayer.java | 21 ++++++++++++++----- .../newpipe/player/MainVideoPlayer.java | 4 ++-- .../newpipe/player/PopupVideoPlayer.java | 8 ++++--- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java index 5ef890579..7a9a0eb3a 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java @@ -216,7 +216,7 @@ public final class BackgroundPlayer extends Service { remoteViews.setOnClickPendingIntent(R.id.notificationFForward, PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_FAST_FORWARD), PendingIntent.FLAG_UPDATE_CURRENT)); - setRepeatModeIcon(remoteViews, basePlayerImpl.simpleExoPlayer.getRepeatMode()); + setRepeatModeIcon(remoteViews, basePlayerImpl.getRepeatMode()); } /** @@ -489,7 +489,7 @@ public final class BackgroundPlayer extends Service { private void updatePlayback() { if (activityListener != null && simpleExoPlayer != null && playQueue != null) { - activityListener.onPlaybackUpdate(currentState, simpleExoPlayer.getRepeatMode(), playQueue.isShuffled(), simpleExoPlayer.getPlaybackParameters()); + activityListener.onPlaybackUpdate(currentState, getRepeatMode(), playQueue.isShuffled(), getPlaybackParameters()); } } diff --git a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java index 114ed8f7f..2c0c05d66 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java @@ -255,14 +255,17 @@ public abstract class BasePlayer implements Player.EventListener, return; } - setPlaybackSpeed(intent.getFloatExtra(PLAYBACK_SPEED, getPlaybackSpeed())); - setPlaybackPitch(intent.getFloatExtra(PLAYBACK_PITCH, getPlaybackPitch())); + final int repeatMode = intent.getIntExtra(REPEAT_MODE, getRepeatMode()); + final float playbackSpeed = intent.getFloatExtra(PLAYBACK_SPEED, getPlaybackSpeed()); + final float playbackPitch = intent.getFloatExtra(PLAYBACK_PITCH, getPlaybackPitch()); // Re-initialization destroyPlayer(); if (playQueue != null) playQueue.dispose(); if (playbackManager != null) playbackManager.dispose(); initPlayer(); + setRepeatMode(repeatMode); + setPlaybackParameters(playbackSpeed, playbackPitch); // Good to go... initPlayback(this, queue); @@ -534,7 +537,7 @@ public abstract class BasePlayer implements Player.EventListener, final int mode; - switch (simpleExoPlayer.getRepeatMode()) { + switch (getRepeatMode()) { case Player.REPEAT_MODE_OFF: mode = Player.REPEAT_MODE_ONE; break; @@ -547,8 +550,8 @@ public abstract class BasePlayer implements Player.EventListener, break; } - simpleExoPlayer.setRepeatMode(mode); - if (DEBUG) Log.d(TAG, "onRepeatClicked() currentRepeatMode = " + simpleExoPlayer.getRepeatMode()); + setRepeatMode(mode); + if (DEBUG) Log.d(TAG, "onRepeatClicked() currentRepeatMode = " + getRepeatMode()); } public void onShuffleClicked() { @@ -982,6 +985,14 @@ public abstract class BasePlayer implements Player.EventListener, return simpleExoPlayer.getPlaybackState() == Player.STATE_READY && simpleExoPlayer.getPlayWhenReady(); } + public int getRepeatMode() { + return simpleExoPlayer.getRepeatMode(); + } + + public void setRepeatMode(final int repeatMode) { + simpleExoPlayer.setRepeatMode(repeatMode); + } + public float getPlaybackSpeed() { return getPlaybackParameters().speed; } diff --git a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java index 4a4de3d05..f41c88f54 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java @@ -342,7 +342,7 @@ public final class MainVideoPlayer extends Activity { context, PopupVideoPlayer.class, this.getPlayQueue(), - this.simpleExoPlayer.getRepeatMode(), + this.getRepeatMode(), this.getPlaybackSpeed(), this.getPlaybackPitch(), this.getPlaybackQuality() @@ -580,7 +580,7 @@ public final class MainVideoPlayer extends Activity { if (repeatButton == null || shuffleButton == null || simpleExoPlayer == null || playQueue == null) return; - setRepeatModeButton(repeatButton, simpleExoPlayer.getRepeatMode()); + setRepeatModeButton(repeatButton, getRepeatMode()); setShuffleButton(shuffleButton, playQueue.isShuffled()); } diff --git a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java index 34b223f2b..9baee3a8b 100644 --- a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java @@ -277,7 +277,7 @@ public final class PopupVideoPlayer extends Service { notRemoteView.setOnClickPendingIntent(R.id.notificationRepeat, PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_REPEAT), PendingIntent.FLAG_UPDATE_CURRENT)); - setRepeatModeRemote(notRemoteView, playerImpl.simpleExoPlayer.getRepeatMode()); + setRepeatModeRemote(notRemoteView, playerImpl.getRepeatMode()); return new NotificationCompat.Builder(this, getString(R.string.notification_channel_id)) .setOngoing(true) @@ -379,6 +379,8 @@ public final class PopupVideoPlayer extends Service { } protected void setRepeatModeRemote(final RemoteViews remoteViews, final int repeatMode) { + if (remoteViews == null) return; + switch (repeatMode) { case Player.REPEAT_MODE_OFF: remoteViews.setInt(R.id.notificationRepeat, setImageResourceMethodName, R.drawable.exo_controls_repeat_off); @@ -439,7 +441,7 @@ public final class PopupVideoPlayer extends Service { context, MainVideoPlayer.class, this.getPlayQueue(), - this.simpleExoPlayer.getRepeatMode(), + this.getRepeatMode(), this.getPlaybackSpeed(), this.getPlaybackPitch(), this.getPlaybackQuality() @@ -545,7 +547,7 @@ public final class PopupVideoPlayer extends Service { private void updatePlayback() { if (activityListener != null && simpleExoPlayer != null && playQueue != null) { - activityListener.onPlaybackUpdate(currentState, simpleExoPlayer.getRepeatMode(), playQueue.isShuffled(), simpleExoPlayer.getPlaybackParameters()); + activityListener.onPlaybackUpdate(currentState, getRepeatMode(), playQueue.isShuffled(), simpleExoPlayer.getPlaybackParameters()); } }