Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to fast forward and rewind #581

Merged
merged 7 commits into from
Oct 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -570,14 +570,14 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
// Control fast forward and rewind if overlay hidden and not showing live TV
if (!mPlaybackController.isLiveTv()) {
if (keyCode == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD || keyCode == KeyEvent.KEYCODE_BUTTON_R1 || keyCode == KeyEvent.KEYCODE_BUTTON_R2) {
mPlaybackController.skip(30000);
mPlaybackController.fastForward();
if (!mIsVisible) show();
setFadingEnabled(true);
return true;
}

if (keyCode == KeyEvent.KEYCODE_MEDIA_REWIND || keyCode == KeyEvent.KEYCODE_BUTTON_L1 || keyCode == KeyEvent.KEYCODE_BUTTON_L2) {
mPlaybackController.skip(-11000);
mPlaybackController.rewind();
if (!mIsVisible) show();
setFadingEnabled(true);
return true;
Expand All @@ -589,12 +589,16 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
Utils.beep(100);
mPlaybackController.skip(30000);
mIsVisible = true;
setFadingEnabled(true);
return true;
}

if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
Utils.beep(100);
mPlaybackController.skip(-11000);
mIsVisible = true;
setFadingEnabled(true);
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ public class PlaybackController {
private Runnable mReportLoop;
private Handler mHandler;

private long lastFF = 0;
private long lastRewind = 0;

private long startTime = 0;
private int baseSkip = 5000;
private int speedMultiplier = 1;

private long mStartPosition = 0;
private long mCurrentProgramEndTime;
private long mCurrentProgramStartTime;
Expand Down Expand Up @@ -832,13 +839,36 @@ public void onError(Exception exception) {
public void run() {
if (!isPlaying()) return; // in case we completed since this was requested

seek(currentSkipPos);
currentSkipPos = 0;
startReportLoop();
updateProgress = true; // re-enable true progress updates
}
};

public void rewind() {
long curTime = System.currentTimeMillis();
if (curTime - lastRewind > 2000) {
startTime = curTime;
speedMultiplier = 1;
}
speedMultiplier = ((int)(curTime - startTime) / 4000) + 1;
if (speedMultiplier > 6)
speedMultiplier = 6;
skip(-(baseSkip*speedMultiplier));
lastRewind = curTime;
}

public void fastForward() {
long curTime = System.currentTimeMillis();
if (curTime - lastFF > 2000) {
startTime = curTime;
speedMultiplier = 1;
}
speedMultiplier = ((int)(curTime - startTime) / 4000) + 1;
if (speedMultiplier > 6)
speedMultiplier = 6;
skip((baseSkip*speedMultiplier));
lastFF = curTime;
}

public void skip(int msec) {
if (isPlaying() && spinnerOff && mVideoManager.getCurrentPosition() > 0) { //guard against skipping before playback has truly begun
mHandler.removeCallbacks(skipRunnable);
Expand All @@ -850,6 +880,9 @@ public void skip(int msec) {
Timber.d("Duration reported as: %s current pos: %s",mVideoManager.getDuration(), mVideoManager.getCurrentPosition());
if (currentSkipPos > mVideoManager.getDuration()) currentSkipPos = mVideoManager.getDuration() - 1000;
mFragment.setCurrentTime(currentSkipPos);
seek(currentSkipPos);
currentSkipPos = 0;
updateProgress = true; // re-enable true progress updates
mHandler.postDelayed(skipRunnable, 800);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public void pause() {

@Override
public void rewind() {
playbackController.skip(-30000);
playbackController.rewind();
updateCurrentPosition();
}

@Override
public void fastForward() {
playbackController.skip(30000);
playbackController.fastForward();
updateCurrentPosition();
}

Expand Down