From d82274f5d431fb17a8f7f146afbfb8b2d6722e4a Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sat, 27 Oct 2018 09:57:11 +0200 Subject: [PATCH] fucking android bullshit --- .../org/schabi/newpipe/player/BasePlayer.java | 28 +++---------------- .../newpipe/player/MainVideoPlayer.java | 15 +++++++--- .../metadata/android/en-US/changelogs/69.txt | 3 ++ 3 files changed, 18 insertions(+), 28 deletions(-) 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 e44b4d3cb..0e4d07179 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java @@ -145,10 +145,6 @@ public abstract class BasePlayer implements @Nullable protected Toast errorToast; - /** Will remember the last playback state even if simpleExoPlayer ot destroyed */ - private int lastPlaybackState; - private boolean lastPlayWhenReady; - /*////////////////////////////////////////////////////////////////////////// // Player //////////////////////////////////////////////////////////////////////////*/ @@ -277,8 +273,6 @@ public abstract class BasePlayer implements public void destroyPlayer() { if (DEBUG) Log.d(TAG, "destroyPlayer() called"); if (simpleExoPlayer != null) { - lastPlaybackState = simpleExoPlayer.getPlaybackState(); - lastPlayWhenReady = simpleExoPlayer.getPlayWhenReady(); simpleExoPlayer.removeListener(this); simpleExoPlayer.stop(); simpleExoPlayer.release(); @@ -1112,9 +1106,9 @@ public abstract class BasePlayer implements } public boolean isPlaying() { - final int state = getLastPlaybackState(); + final int state = simpleExoPlayer.getPlaybackState(); return (state == Player.STATE_READY || state == Player.STATE_BUFFERING) - && getLastPlayWhenReady(); + && simpleExoPlayer.getPlayWhenReady(); } @Player.RepeatMode @@ -1188,21 +1182,7 @@ public abstract class BasePlayer implements playQueue.setRecovery(queuePos, windowPos); } - /** - * Sometimes the playbac kstate gets asked even though simpleExoPlayer got already destroyed. - * Therefore on destroying simpleExoPlayer the playback state will get asked once more, so - * you can retreve the last playback state here. - * @return the playback state of simpleExoPlayer even if got destroyed - */ - public int getLastPlaybackState() { - return simpleExoPlayer == null - ? lastPlaybackState - : simpleExoPlayer.getPlaybackState(); - } - - public boolean getLastPlayWhenReady() { - return simpleExoPlayer == null - ? lastPlayWhenReady - : simpleExoPlayer.getPlayWhenReady(); + public boolean gotDestroyed() { + return simpleExoPlayer == null; } } 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 71b724228..07a9ac71c 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java @@ -217,10 +217,9 @@ public final class MainVideoPlayer extends AppCompatActivity if (playerImpl == null) return; playerImpl.setRecovery(); - playerState = new PlayerState(playerImpl.getPlayQueue(), playerImpl.getRepeatMode(), - playerImpl.getPlaybackSpeed(), playerImpl.getPlaybackPitch(), - playerImpl.getPlaybackQuality(), playerImpl.getPlaybackSkipSilence(), - playerImpl.isPlaying()); + if(!playerImpl.gotDestroyed()) { + playerState = createPlayerState(); + } StateSaver.tryToSave(isChangingConfigurations(), null, outState, this); } @@ -235,6 +234,7 @@ public final class MainVideoPlayer extends AppCompatActivity if (!isBackPressed) { playerImpl.minimize(); } + playerState = createPlayerState(); playerImpl.destroy(); isInMultiWindow = false; @@ -245,6 +245,13 @@ public final class MainVideoPlayer extends AppCompatActivity // State Saving //////////////////////////////////////////////////////////////////////////*/ + private PlayerState createPlayerState() { + return new PlayerState(playerImpl.getPlayQueue(), playerImpl.getRepeatMode(), + playerImpl.getPlaybackSpeed(), playerImpl.getPlaybackPitch(), + playerImpl.getPlaybackQuality(), playerImpl.getPlaybackSkipSilence(), + playerImpl.isPlaying()); + } + @Override public String generateSuffix() { return "." + UUID.randomUUID().toString() + ".player"; diff --git a/fastlane/metadata/android/en-US/changelogs/69.txt b/fastlane/metadata/android/en-US/changelogs/69.txt index d3fa66292..c8262d1b0 100644 --- a/fastlane/metadata/android/en-US/changelogs/69.txt +++ b/fastlane/metadata/android/en-US/changelogs/69.txt @@ -14,3 +14,6 @@ - Fix time parsing for . format, so NewPipe can be used in Finland - Fix subscription count - Add foreground service permission for API 28+ devices #1830 + +### Known Bugs +- Playback state can not be saved on Android P