From 6092f06d4642f2e8d054c3201eb69b81eb980482 Mon Sep 17 00:00:00 2001 From: MaX-Lo Date: Sat, 22 Sep 2018 11:32:13 +0200 Subject: [PATCH 1/2] store the last used aspect ratio in SharedPreferences and reload them on resuming the VideoPlayer Activity (similar to storing/reloading the last used: screen rotation) --- .../newpipe/player/MainVideoPlayer.java | 23 ++++++++++++++++--- .../schabi/newpipe/player/VideoPlayer.java | 9 ++++++-- app/src/main/res/values/settings_keys.xml | 2 ++ 3 files changed, 29 insertions(+), 5 deletions(-) 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 4e8398ff2..8ce18fa56 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java @@ -175,6 +175,10 @@ public final class MainVideoPlayer extends AppCompatActivity setLandscape(lastOrientationWasLandscape); } + final int lastResizeMode = defaultPreferences.getInt( + getString(R.string.last_resize_mode), AspectRatioFrameLayout.RESIZE_MODE_FIT); + playerImpl.setResizeMode(lastResizeMode); + // Upon going in or out of multiwindow mode, isInMultiWindow will always be false, // since the first onResume needs to restore the player. // Subsequent onResume calls while multiwindow mode remains the same and the player is @@ -705,14 +709,27 @@ public final class MainVideoPlayer extends AppCompatActivity @Override protected int nextResizeMode(int currentResizeMode) { + final int newResizeMode; switch (currentResizeMode) { case AspectRatioFrameLayout.RESIZE_MODE_FIT: - return AspectRatioFrameLayout.RESIZE_MODE_FILL; + newResizeMode = AspectRatioFrameLayout.RESIZE_MODE_FILL; + break; case AspectRatioFrameLayout.RESIZE_MODE_FILL: - return AspectRatioFrameLayout.RESIZE_MODE_ZOOM; + newResizeMode = AspectRatioFrameLayout.RESIZE_MODE_ZOOM; + break; default: - return AspectRatioFrameLayout.RESIZE_MODE_FIT; + newResizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT; + break; } + + storeResizeMode(newResizeMode); + return newResizeMode; + } + + private void storeResizeMode(@AspectRatioFrameLayout.ResizeMode int resizeMode) { + defaultPreferences.edit() + .putInt(getString(R.string.last_resize_mode), resizeMode) + .apply(); } @Override diff --git a/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java index 679fc6645..6bcbf58de 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java @@ -683,12 +683,17 @@ public abstract class VideoPlayer extends BasePlayer if (getAspectRatioFrameLayout() != null) { final int currentResizeMode = getAspectRatioFrameLayout().getResizeMode(); final int newResizeMode = nextResizeMode(currentResizeMode); - getAspectRatioFrameLayout().setResizeMode(newResizeMode); - getResizeView().setText(PlayerHelper.resizeTypeOf(context, newResizeMode)); + setResizeMode(newResizeMode); } } + protected void setResizeMode(@AspectRatioFrameLayout.ResizeMode final int resizeMode) { + getAspectRatioFrameLayout().setResizeMode(resizeMode); + getResizeView().setText(PlayerHelper.resizeTypeOf(context, resizeMode)); + } + protected abstract int nextResizeMode(@AspectRatioFrameLayout.ResizeMode final int resizeMode); + /*////////////////////////////////////////////////////////////////////////// // SeekBar Listener //////////////////////////////////////////////////////////////////////////*/ diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 9b39fec26..f01bdb366 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -105,6 +105,8 @@ last_orientation_landscape_key + last_resize_mode + debug_pref_screen_key allow_heap_dumping_key From 0510db75fb99166537e632521e9d500998c5aee5 Mon Sep 17 00:00:00 2001 From: Coin Date: Wed, 3 Oct 2018 00:31:28 +0800 Subject: [PATCH 2/2] Enqueuing now triggers video playing if the play queue has done playing --- app/src/main/java/org/schabi/newpipe/player/BasePlayer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 01a0614fa..f5f843caa 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java @@ -230,7 +230,8 @@ public abstract class BasePlayer implements int sizeBeforeAppend = playQueue.size(); playQueue.append(queue.getStreams()); - if (intent.getBooleanExtra(SELECT_ON_APPEND, false) && + if ((intent.getBooleanExtra(SELECT_ON_APPEND, false) || + getCurrentState() == STATE_COMPLETED) && queue.getStreams().size() > 0) { playQueue.setIndex(sizeBeforeAppend); }