fix(fix-playback): seek to maximum end

This commit is contained in:
oSumAtrIX 2022-11-05 06:24:32 +01:00
parent 6aa0ca9556
commit fd69010def
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4

View File

@ -1,34 +1,38 @@
package app.revanced.integrations.patches; package app.revanced.integrations.patches;
import java.util.Timer;
import app.revanced.integrations.settings.SettingsEnum; import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.utils.LogHelper; import app.revanced.integrations.utils.LogHelper;
public final class FixPlaybackPatch { public final class FixPlaybackPatch {
private static Thread currentThread = null; private static Thread currentThread = null;
public static void newVideoLoaded(final String _videoId) { private static String videoId;
public static void newVideoLoaded(final String videoId) {
if (!SettingsEnum.FIX_PLAYBACK.getBoolean()) return; if (!SettingsEnum.FIX_PLAYBACK.getBoolean()) return;
if (videoId.equals(FixPlaybackPatch.videoId)) return;
else FixPlaybackPatch.videoId = videoId;
if (currentThread != null) { if (currentThread != null) {
currentThread.interrupt(); currentThread.interrupt();
} }
currentThread = new Thread(() -> { currentThread = new Thread(() -> {
try {
while (true) { while (true) {
var currentVideoLength = PlayerControllerPatch.getCurrentVideoLength(); var currentVideoTime = VideoInformation.getVideoTime();
if (currentVideoLength > 1) {
PlayerControllerPatch.seekTo(currentVideoLength); if (currentVideoTime > -1) {
PlayerControllerPatch.seekTo(1); VideoInformation.seekTo(Integer.MAX_VALUE);
VideoInformation.seekTo(currentVideoTime);
return; return;
} }
try {
Thread.sleep(10); Thread.sleep(10);
}
} catch (InterruptedException e) { } catch (InterruptedException e) {
LogHelper.debug(FixPlaybackPatch.class, "Thread was interrupted"); LogHelper.debug(FixPlaybackPatch.class, "Thread was interrupted");
} }
}
}); });
currentThread.start(); currentThread.start();