1
mirror of https://github.com/revanced/revanced-integrations synced 2024-11-22 05:02:19 +01:00

fix(YouTube - VideoInformation): Ignore video seek attempts during the last 250ms of video playback

This commit is contained in:
LisoUseInAIKyrios 2023-12-26 23:29:12 +04:00
parent 14396fc2c0
commit 6263edce11

View File

@ -157,20 +157,29 @@ public final class VideoInformation {
* Caution: If called from a videoTimeHook() callback,
* this will cause a recursive call into the same videoTimeHook() callback.
*
* @param millisecond The millisecond to seek the video to.
* @param seekTime The seekTime to seek the video to.
* @return true if the seek was successful.
*/
public static boolean seekTo(final long millisecond) {
public static boolean seekTo(final long seekTime) {
ReVancedUtils.verifyOnMainThread();
try {
final long videoTime = getVideoTime();
final long videoLength = getVideoLength();
// Prevent issues such as play/ pause button or autoplay not working.
final long seekToMilliseconds = Math.min(millisecond, VideoInformation.getVideoLength() - 250);
final long adjustedSeekTime = Math.min(seekTime, videoLength - 250);
if (videoTime <= seekTime && videoTime >= adjustedSeekTime) {
// Both the current video time and the seekTo are in the last 250ms of the video.
// Ignore this seek call, otherwise if a video ends with multiple closely timed segments
// then seeking here can create an infinite loop of skip attempts.
LogHelper.printDebug(() -> "Ignoring seekTo call as video playback is almost finished. "
+ " videoTime: " + videoTime + " videoLength: " + videoLength + " seekTo: " + seekTime);
return false;
}
ReVancedUtils.verifyOnMainThread();
try {
LogHelper.printDebug(() -> "Seeking to " + seekToMilliseconds);
LogHelper.printDebug(() -> "Seeking to " + adjustedSeekTime);
//noinspection DataFlowIssue
return (Boolean) seekMethod.invoke(playerControllerRef.get(), seekToMilliseconds);
return (Boolean) seekMethod.invoke(playerControllerRef.get(), adjustedSeekTime);
} catch (Exception ex) {
LogHelper.printException(() -> "Failed to seek", ex);
return false;