From f557bf15d1f66c9355d625c171248a6c453f5cea Mon Sep 17 00:00:00 2001 From: Niels van Velzen Date: Sun, 13 Oct 2024 13:48:46 +0200 Subject: [PATCH] Fix skipping to next episode --- .../playback/CustomPlaybackOverlayFragment.java | 17 ++++++++++------- .../ui/playback/PlaybackController.java | 14 +++++++++++++- .../ui/playback/PlaybackControllerHelper.kt | 2 +- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/jellyfin/androidtv/ui/playback/CustomPlaybackOverlayFragment.java b/app/src/main/java/org/jellyfin/androidtv/ui/playback/CustomPlaybackOverlayFragment.java index d985a8b40f..008c9afff5 100644 --- a/app/src/main/java/org/jellyfin/androidtv/ui/playback/CustomPlaybackOverlayFragment.java +++ b/app/src/main/java/org/jellyfin/androidtv/ui/playback/CustomPlaybackOverlayFragment.java @@ -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; @@ -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; } } @@ -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; } @@ -1291,6 +1288,9 @@ private void prepareChannelAdapter() { } public void closePlayer() { + if (navigating) return; + navigating = true; + if (navigationRepository.getValue().getCanGoBack()) { navigationRepository.getValue().goBack(); } else { @@ -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); } diff --git a/app/src/main/java/org/jellyfin/androidtv/ui/playback/PlaybackController.java b/app/src/main/java/org/jellyfin/androidtv/ui/playback/PlaybackController.java index 06a0c0707b..f9569060d4 100644 --- a/app/src/main/java/org/jellyfin/androidtv/ui/playback/PlaybackController.java +++ b/app/src/main/java/org/jellyfin/androidtv/ui/playback/PlaybackController.java @@ -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()); @@ -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; diff --git a/app/src/main/java/org/jellyfin/androidtv/ui/playback/PlaybackControllerHelper.kt b/app/src/main/java/org/jellyfin/androidtv/ui/playback/PlaybackControllerHelper.kt index 5a17bc34ea..461136b5af 100644 --- a/app/src/main/java/org/jellyfin/androidtv/ui/playback/PlaybackControllerHelper.kt +++ b/app/src/main/java/org/jellyfin/androidtv/ui/playback/PlaybackControllerHelper.kt @@ -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