Skip to content

Commit

Permalink
fix(YouTube/SponsorBlock): some videos refused to end where there's a…
Browse files Browse the repository at this point in the history
… skippable segment at the end
  • Loading branch information
inotia00 committed Dec 3, 2023
1 parent c21edf3 commit 206b9ba
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ public class SponsorSegment implements Comparable<SponsorSegment> {
*/
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;
}

Expand Down

0 comments on commit 206b9ba

Please sign in to comment.