diff --git a/app/src/main/java/app/revanced/integrations/patches/video/VideoInformation.java b/app/src/main/java/app/revanced/integrations/patches/video/VideoInformation.java index 42f8dfc892..eda67662d0 100644 --- a/app/src/main/java/app/revanced/integrations/patches/video/VideoInformation.java +++ b/app/src/main/java/app/revanced/integrations/patches/video/VideoInformation.java @@ -62,17 +62,10 @@ public static void initialize(@NonNull Object playerController) { * @return if the seek was successful */ public static boolean seekTo(long millisecond) { - final long videoLength = getVideoLength(); - - // Don't seek more than the video length to prevent issues such as - // Play pause button or autoplay not working. - // TODO: These are arbitrarily chosen values and should be subject to be adjusted. - final long seekToMilliseconds = millisecond > videoLength ? Integer.MAX_VALUE : millisecond; - ReVancedUtils.verifyOnMainThread(); try { //noinspection DataFlowIssue - return (Boolean) seekMethod.invoke(playerControllerRef.get(), seekToMilliseconds); + return (Boolean) seekMethod.invoke(playerControllerRef.get(), millisecond); } catch (Exception ex) { LogHelper.printException(() -> "Failed to seek", ex); } diff --git a/app/src/main/java/app/revanced/integrations/sponsorblock/objects/SponsorSegment.java b/app/src/main/java/app/revanced/integrations/sponsorblock/objects/SponsorSegment.java index 7502fbca70..a4d507f652 100644 --- a/app/src/main/java/app/revanced/integrations/sponsorblock/objects/SponsorSegment.java +++ b/app/src/main/java/app/revanced/integrations/sponsorblock/objects/SponsorSegment.java @@ -27,11 +27,17 @@ public class SponsorSegment implements Comparable { */ public boolean recordedAsSkipped = false; + /** + * The end of the segment may be longer than the length of the video. + * In this case, the autoplay may break or fall into an infinite loop. + * Checking the length every time in {@link VideoInformation#seekTo} is too inefficient, + * So check it only once when the segment is fetched. + */ public SponsorSegment(@NonNull SegmentCategory category, @Nullable String UUID, long start, long end, boolean isLocked) { this.category = category; this.UUID = UUID; this.start = start; - this.end = end; + this.end = Math.min(end, VideoInformation.getVideoLength() - 250); this.isLocked = isLocked; }