diff --git a/app/build.gradle b/app/build.gradle index b04daebed..6410cb823 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -42,7 +42,7 @@ android { ext { supportLibVersion = '27.1.1' - exoPlayerLibVersion = '2.8.0' + exoPlayerLibVersion = '2.8.1' roomDbLibVersion = '1.1.1' leakCanaryLibVersion = '1.5.4' okHttpLibVersion = '3.10.0' 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 c5c9f0615..231163b7b 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java @@ -544,26 +544,29 @@ public final class BackgroundPlayer extends Service { @Override public void changeState(int state) { + resetNotification(); super.changeState(state); updatePlayback(); - updateNotification(-1); } @Override public void onBlocked() { super.onBlocked(); + updateNotification(-1); startForeground(NOTIFICATION_ID, notBuilder.build()); } @Override public void onBuffering() { super.onBuffering(); + updateNotification(-1); startForeground(NOTIFICATION_ID, notBuilder.build()); } @Override public void onPausedSeek() { super.onPausedSeek(); + updateNotification(-1); startForeground(NOTIFICATION_ID, notBuilder.build()); } @@ -589,7 +592,6 @@ public final class BackgroundPlayer extends Service { public void onCompleted() { super.onCompleted(); - resetNotification(); if (bigNotRemoteView != null) bigNotRemoteView.setProgressBar(R.id.notificationProgressBar, 100, 100, false); if (notRemoteView != null) notRemoteView.setProgressBar(R.id.notificationProgressBar, 100, 100, false); updateNotification(R.drawable.ic_replay_white); 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 3f50cf149..113ccbf68 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java @@ -85,7 +85,6 @@ import static com.google.android.exoplayer2.Player.DISCONTINUITY_REASON_INTERNAL import static com.google.android.exoplayer2.Player.DISCONTINUITY_REASON_PERIOD_TRANSITION; import static com.google.android.exoplayer2.Player.DISCONTINUITY_REASON_SEEK; import static com.google.android.exoplayer2.Player.DISCONTINUITY_REASON_SEEK_ADJUSTMENT; -import static org.schabi.newpipe.player.helper.PlayerHelper.getTimeString; /** * Base for the players, joining the common properties @@ -157,7 +156,6 @@ public abstract class BasePlayer implements protected MediaSessionManager mediaSessionManager; private boolean isPrepared = false; - private boolean isSynchronizing = false; //////////////////////////////////////////////////////////////////////////*/ @@ -575,37 +573,17 @@ public abstract class BasePlayer implements private void maybeCorrectSeekPosition() { if (playQueue == null || simpleExoPlayer == null || currentMetadata == null) return; - final int currentSourceIndex = playQueue.getIndex(); final PlayQueueItem currentSourceItem = playQueue.getItem(); - final StreamInfo currentInfo = currentMetadata.getMetadata(); - if (currentSourceItem == null) return; - final long recoveryPositionMillis = currentSourceItem.getRecoveryPosition(); - final boolean isCurrentWindowCorrect = - simpleExoPlayer.getCurrentPeriodIndex() == currentSourceIndex; + final StreamInfo currentInfo = currentMetadata.getMetadata(); final long presetStartPositionMillis = currentInfo.getStartPosition() * 1000; - - if (recoveryPositionMillis != PlayQueueItem.RECOVERY_UNSET && isCurrentWindowCorrect) { - // Is recovering previous playback? - if (DEBUG) Log.d(TAG, "Playback - Rewinding to recovery time=" + - "[" + getTimeString((int)recoveryPositionMillis) + "]"); - seekTo(recoveryPositionMillis); - playQueue.unsetRecovery(currentSourceIndex); - - } else if (isSynchronizing && isLive()) { - // Is still synchronizing? - if (DEBUG) Log.d(TAG, "Playback - Synchronizing livestream to default time"); - //seekToDefault(); - - } else if (isSynchronizing && presetStartPositionMillis > 0L) { + if (presetStartPositionMillis > 0L) { // Has another start position? if (DEBUG) Log.d(TAG, "Playback - Seeking to preset start " + "position=[" + presetStartPositionMillis + "]"); seekTo(presetStartPositionMillis); } - - isSynchronizing = false; } /** @@ -784,16 +762,18 @@ public abstract class BasePlayer implements "index=[" + currentPlayQueueIndex + "] with " + "playlist length=[" + currentPlaylistSize + "]"); - // If not playing correct stream, change window position and sets flag - // for synchronizing once window position is corrected - // @see maybeCorrectSeekPosition() } else if (currentPlaylistIndex != currentPlayQueueIndex || onPlaybackInitial || !isPlaying()) { if (DEBUG) Log.d(TAG, "Playback - Rewinding to correct" + " index=[" + currentPlayQueueIndex + "]," + " from=[" + currentPlaylistIndex + "], size=[" + currentPlaylistSize + "]."); - isSynchronizing = true; - simpleExoPlayer.seekToDefaultPosition(currentPlayQueueIndex); + + if (item.getRecoveryPosition() != PlayQueueItem.RECOVERY_UNSET) { + simpleExoPlayer.seekTo(currentPlayQueueIndex, item.getRecoveryPosition()); + playQueue.unsetRecovery(currentPlayQueueIndex); + } else { + simpleExoPlayer.seekToDefaultPosition(currentPlayQueueIndex); + } } } @@ -936,9 +916,7 @@ public abstract class BasePlayer implements public void seekTo(long positionMillis) { if (DEBUG) Log.d(TAG, "seekBy() called with: position = [" + positionMillis + "]"); - if (simpleExoPlayer == null || positionMillis < 0 || - positionMillis > simpleExoPlayer.getDuration()) return; - simpleExoPlayer.seekTo(positionMillis); + if (simpleExoPlayer != null) simpleExoPlayer.seekTo(positionMillis); } public void seekBy(long offsetMillis) { 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 9130ea009..bf728f9d5 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java @@ -896,7 +896,6 @@ public final class MainVideoPlayer extends AppCompatActivity @Override public boolean onDoubleTap(MotionEvent e) { if (DEBUG) Log.d(TAG, "onDoubleTap() called with: e = [" + e + "]" + "rawXy = " + e.getRawX() + ", " + e.getRawY() + ", xy = " + e.getX() + ", " + e.getY()); - if (!playerImpl.isPlaying()) return false; if (e.getX() > playerImpl.getRootView().getWidth() * 2 / 3) { playerImpl.onFastForward(); 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 0426525a4..e2929d26f 100644 --- a/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/PopupVideoPlayer.java @@ -683,9 +683,9 @@ public final class PopupVideoPlayer extends Service { @Override public void changeState(int state) { + resetNotification(); super.changeState(state); updatePlayback(); - updateNotification(-1); } @Override diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java index c53680835..c184da0a5 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java @@ -27,7 +27,13 @@ public class PlaybackParameterDialog extends DialogFragment { public static final char STEP_UP_SIGN = '+'; public static final char STEP_DOWN_SIGN = '-'; - public static final double DEFAULT_PLAYBACK_STEP_VALUE = 0.05f; + + public static final double STEP_ONE_PERCENT_VALUE = 0.01f; + public static final double STEP_FIVE_PERCENT_VALUE = 0.05f; + public static final double STEP_TEN_PERCENT_VALUE = 0.10f; + public static final double STEP_TWENTY_FIVE_PERCENT_VALUE = 0.25f; + public static final double STEP_ONE_HUNDRED_PERCENT_VALUE = 1.00f; + public static final double DEFAULT_PLAYBACK_STEP_VALUE = STEP_TWENTY_FIVE_PERCENT_VALUE; public static final double DEFAULT_TEMPO = 1.00f; public static final double DEFAULT_PITCH = 1.00f; @@ -244,35 +250,33 @@ public class PlaybackParameterDialog extends DialogFragment { stepSizeOneHundredPercentText = rootView.findViewById(R.id.stepSizeOneHundredPercent); if (stepSizeOnePercentText != null) { - final double onePercent = 0.01f; - stepSizeOnePercentText.setText(getPercentString(onePercent)); - stepSizeOnePercentText.setOnClickListener(view -> setupStepSize(onePercent)); + stepSizeOnePercentText.setText(getPercentString(STEP_ONE_PERCENT_VALUE)); + stepSizeOnePercentText.setOnClickListener(view -> + setupStepSize(STEP_ONE_PERCENT_VALUE)); } if (stepSizeFivePercentText != null) { - final double fivePercent = 0.05f; - stepSizeFivePercentText.setText(getPercentString(fivePercent)); - stepSizeFivePercentText.setOnClickListener(view -> setupStepSize(fivePercent)); + stepSizeFivePercentText.setText(getPercentString(STEP_FIVE_PERCENT_VALUE)); + stepSizeFivePercentText.setOnClickListener(view -> + setupStepSize(STEP_FIVE_PERCENT_VALUE)); } if (stepSizeTenPercentText != null) { - final double tenPercent = 0.10f; - stepSizeTenPercentText.setText(getPercentString(tenPercent)); - stepSizeTenPercentText.setOnClickListener(view -> setupStepSize(tenPercent)); + stepSizeTenPercentText.setText(getPercentString(STEP_TEN_PERCENT_VALUE)); + stepSizeTenPercentText.setOnClickListener(view -> + setupStepSize(STEP_TEN_PERCENT_VALUE)); } if (stepSizeTwentyFivePercentText != null) { - final double twentyFivePercent = 0.25f; - stepSizeTwentyFivePercentText.setText(getPercentString(twentyFivePercent)); + stepSizeTwentyFivePercentText.setText(getPercentString(STEP_TWENTY_FIVE_PERCENT_VALUE)); stepSizeTwentyFivePercentText.setOnClickListener(view -> - setupStepSize(twentyFivePercent)); + setupStepSize(STEP_TWENTY_FIVE_PERCENT_VALUE)); } if (stepSizeOneHundredPercentText != null) { - final double oneHundredPercent = 1.00f; - stepSizeOneHundredPercentText.setText(getPercentString(oneHundredPercent)); + stepSizeOneHundredPercentText.setText(getPercentString(STEP_ONE_HUNDRED_PERCENT_VALUE)); stepSizeOneHundredPercentText.setOnClickListener(view -> - setupStepSize(oneHundredPercent)); + setupStepSize(STEP_ONE_HUNDRED_PERCENT_VALUE)); } }