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

Fix skipping to next episode #4072

Merged
merged 1 commit into from
Oct 13, 2024
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 @@ -123,6 +123,7 @@ public class CustomPlaybackOverlayFragment extends Fragment implements LiveTvGui
private boolean mFadeEnabled = false;
private boolean mIsVisible = false;
private boolean mPopupPanelVisible = false;
private boolean navigating = false;

private LeanbackOverlayFragment leanbackOverlayFragment;

Expand Down Expand Up @@ -484,9 +485,9 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {

// Hide with seek
if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
playbackControllerContainer.getValue().getPlaybackController().seek(binding.skipOverlay.getTargetPositionMs());
playbackControllerContainer.getValue().getPlaybackController().seek(binding.skipOverlay.getTargetPositionMs(), true);
leanbackOverlayFragment.setShouldShowOverlay(false);
binding.skipOverlay.setTargetPositionMs(null);
if (binding != null) binding.skipOverlay.setTargetPositionMs(null);
return true;
}
}
Expand Down Expand Up @@ -658,11 +659,7 @@ public void onResume() {
// Close player when resuming without a valid playback controller
PlaybackController playbackController = playbackControllerContainer.getValue().getPlaybackController();
if (playbackController == null || !playbackController.hasFragment()) {
if (navigationRepository.getValue().getCanGoBack()) {
navigationRepository.getValue().goBack();
} else {
navigationRepository.getValue().reset(Destinations.INSTANCE.getHome());
}
closePlayer();

return;
}
Expand Down Expand Up @@ -1291,6 +1288,9 @@ private void prepareChannelAdapter() {
}

public void closePlayer() {
if (navigating) return;
navigating = true;

if (navigationRepository.getValue().getCanGoBack()) {
navigationRepository.getValue().goBack();
} else {
Expand All @@ -1299,6 +1299,9 @@ public void closePlayer() {
}

public void showNextUp(@NonNull UUID id) {
if (navigating) return;
navigating = true;

navigationRepository.getValue().navigate(Destinations.INSTANCE.nextUp(id), true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,11 @@ public void rewind() {
}

public void seek(long pos) {
pos = Utils.getSafeSeekPosition(pos, getDuration());
seek(pos, false);
}

public void seek(long pos, boolean skipToNext) {
if (pos <= 0) pos = 0;

Timber.d("Trying to seek from %s to %d", mCurrentPosition, pos);
Timber.d("Container: %s", mCurrentStreamInfo == null ? "unknown" : mCurrentStreamInfo.getContainer());
Expand All @@ -952,6 +956,14 @@ public void seek(long pos) {
}
wasSeeking = true;

// Stop playback when the requested seek position is at the end of the video
if (skipToNext && pos >= (getDuration() - 100)) {
itemComplete();
return;
}

if (pos >= getDuration()) pos = getDuration();

// set seekPosition so real position isn't used until playback starts again
mSeekPosition = pos;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private fun PlaybackController.addSkipAction(mediaSegment: MediaSegmentDto) {
// the seek function in the PlaybackController checks this and optionally starts a transcode
// at the requested position
fragment.lifecycleScope.launch(Dispatchers.Main) {
seek(mediaSegment.end.inWholeMilliseconds)
seek(mediaSegment.end.inWholeMilliseconds, true)
}
}
// Segments at position 0 will never be hit by ExoPlayer so we need to add a minimum value
Expand Down
Loading