mirror of
https://github.com/revanced/revanced-integrations.git
synced 2025-01-07 10:35:49 +01:00
fix(YouTube - SponsorBlock): Skip segments when casting (#655)
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de> Co-authored-by: Hoàng Gia Bảo <70064328+YT-Advanced@users.noreply.github.com> Co-authored-by: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> fix(YouTube - SponsorBlock): Skip segments when casting #655
This commit is contained in:
parent
7aec04647a
commit
5ce16eedc6
@ -23,7 +23,9 @@ public final class VideoInformation {
|
|||||||
private static final String SHORTS_PLAYER_PARAMETERS = "8AEB";
|
private static final String SHORTS_PLAYER_PARAMETERS = "8AEB";
|
||||||
|
|
||||||
private static WeakReference<Object> playerControllerRef;
|
private static WeakReference<Object> playerControllerRef;
|
||||||
|
private static WeakReference<Object> mdxPlayerDirectorRef;
|
||||||
private static Method seekMethod;
|
private static Method seekMethod;
|
||||||
|
private static Method mdxSeekMethod;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private static String videoId = "";
|
private static String videoId = "";
|
||||||
@ -59,6 +61,22 @@ public final class VideoInformation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Injection point.
|
||||||
|
*
|
||||||
|
* @param mdxPlayerDirector MDX player director object (casting mode).
|
||||||
|
*/
|
||||||
|
public static void initializeMdx(@NonNull Object mdxPlayerDirector) {
|
||||||
|
try {
|
||||||
|
mdxPlayerDirectorRef = new WeakReference<>(Objects.requireNonNull(mdxPlayerDirector));
|
||||||
|
|
||||||
|
mdxSeekMethod = mdxPlayerDirector.getClass().getMethod(SEEK_METHOD_NAME, Long.TYPE);
|
||||||
|
mdxSeekMethod.setAccessible(true);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
Logger.printException(() -> "Failed to initialize MDX", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Injection point.
|
* Injection point.
|
||||||
*
|
*
|
||||||
@ -178,8 +196,32 @@ public final class VideoInformation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Logger.printDebug(() -> "Seeking to " + adjustedSeekTime);
|
Logger.printDebug(() -> "Seeking to " + adjustedSeekTime);
|
||||||
//noinspection DataFlowIssue
|
|
||||||
return (Boolean) seekMethod.invoke(playerControllerRef.get(), adjustedSeekTime);
|
try {
|
||||||
|
//noinspection DataFlowIssue
|
||||||
|
if ((Boolean) seekMethod.invoke(playerControllerRef.get(), adjustedSeekTime)) {
|
||||||
|
return true;
|
||||||
|
} // Else the video is loading or changing videos, or video is casting to a different device.
|
||||||
|
} catch (Exception ex) {
|
||||||
|
Logger.printInfo(() -> "seekTo method call failed", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try calling the seekTo method of the MDX player director (called when casting).
|
||||||
|
// The difference has to be a different second mark in order to avoid infinite skip loops
|
||||||
|
// as the Lounge API only supports seconds.
|
||||||
|
if ((adjustedSeekTime / 1000) == (videoTime / 1000)) {
|
||||||
|
Logger.printDebug(() -> "Skipping seekTo for MDX because seek time is too small ("
|
||||||
|
+ (adjustedSeekTime - videoTime) + "ms)");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
//noinspection DataFlowIssue
|
||||||
|
return (Boolean) mdxSeekMethod.invoke(mdxPlayerDirectorRef.get(), adjustedSeekTime);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
Logger.printInfo(() -> "seekTo (MDX) method call failed", ex);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Logger.printException(() -> "Failed to seek", ex);
|
Logger.printException(() -> "Failed to seek", ex);
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user