Skip to content

Commit

Permalink
Pause playback when scrubbing
Browse files Browse the repository at this point in the history
  • Loading branch information
moneytoo committed Mar 24, 2021
1 parent fe042ab commit 7a77d80
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public boolean onTouchEvent(MotionEvent event) {
final int distanceFromScrubber = Math.abs(scrubberBar.right - x);
if (distanceFromScrubber > Utils.dpToPx(24))
return true;
else
scrubbing = true;
}
if (!scrubbing && event.getAction() == MotionEvent.ACTION_MOVE && scrubberBar != null) {
scrubbing = true;
Expand Down
11 changes: 9 additions & 2 deletions app/src/main/java/com/brouken/player/PlayerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ protected void onCreate(Bundle savedInstanceState) {
timeBar.addListener(new TimeBar.OnScrubListener() {
@Override
public void onScrubStart(TimeBar timeBar, long position) {
restorePlayState = player.isPlaying();
if (restorePlayState) {
player.pause();
}
scrubbingNoticeable = false;
isScrubbing = true;
frameRendered = true;
Expand All @@ -202,9 +206,12 @@ public void onScrubMove(TimeBar timeBar, long position) {
@Override
public void onScrubStop(TimeBar timeBar, long position, boolean canceled) {
playerView.setCustomErrorMessage(null);
if (player.isPlaying())
playerView.setControllerShowTimeoutMs(PlayerActivity.CONTROLLER_TIMEOUT);
isScrubbing = false;
if (restorePlayState) {
restorePlayState = false;
playerView.setControllerShowTimeoutMs(PlayerActivity.CONTROLLER_TIMEOUT);
player.setPlayWhenReady(true);
}
}
});

Expand Down

0 comments on commit 7a77d80

Please sign in to comment.