From 6f1fc6116bfe8ad0705f7968933bf2b47f71f010 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Fri, 7 Feb 2025 14:46:49 +0900 Subject: [PATCH] fix(YouTube - Remove background playback restriction): Play/Pause button not working in PiP mode https://github.com/inotia00/ReVanced_Extended/issues/2764 --- .../patches/misc/BackgroundPlaybackPatch.java | 16 +++++++++++++++- .../BackgroundPlaybackPatch.kt | 17 ++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/misc/BackgroundPlaybackPatch.java b/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/misc/BackgroundPlaybackPatch.java index 39dcff1a7..20cb70a4b 100644 --- a/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/misc/BackgroundPlaybackPatch.java +++ b/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/misc/BackgroundPlaybackPatch.java @@ -1,10 +1,14 @@ package app.revanced.extension.youtube.patches.misc; +import app.revanced.extension.shared.settings.BooleanSetting; import app.revanced.extension.youtube.settings.Settings; +import app.revanced.extension.youtube.shared.PlayerType; import app.revanced.extension.youtube.shared.ShortsPlayerState; @SuppressWarnings("unused") public class BackgroundPlaybackPatch { + private static final BooleanSetting DISABLE_SHORTS_BACKGROUND_PLAYBACK = + Settings.DISABLE_SHORTS_BACKGROUND_PLAYBACK; /** * Injection point. @@ -14,11 +18,21 @@ public class BackgroundPlaybackPatch { return ShortsPlayerState.getCurrent().isClosed(); } + /** + * Injection point. + */ + public static boolean isBackgroundShortsPlaybackAllowed() { + if (PlayerType.getCurrent().isNoneHiddenOrMinimized()) { + return !DISABLE_SHORTS_BACKGROUND_PLAYBACK.get(); + } + return false; + } + /** * Injection point. */ public static boolean isBackgroundShortsPlaybackAllowed(boolean original) { - return !Settings.DISABLE_SHORTS_BACKGROUND_PLAYBACK.get(); + return !DISABLE_SHORTS_BACKGROUND_PLAYBACK.get(); } } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/backgroundplayback/BackgroundPlaybackPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/backgroundplayback/BackgroundPlaybackPatch.kt index cf3729409..0401a305f 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/backgroundplayback/BackgroundPlaybackPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/backgroundplayback/BackgroundPlaybackPatch.kt @@ -1,5 +1,6 @@ package app.revanced.patches.youtube.misc.backgroundplayback +import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.extensions.InstructionExtensions.instructions import app.revanced.patcher.patch.bytecodePatch @@ -39,7 +40,7 @@ val backgroundPlaybackPatch = bytecodePatch( arrayOf( backgroundPlaybackManagerFingerprint to "isBackgroundPlaybackAllowed", backgroundPlaybackManagerShortsFingerprint to "isBackgroundShortsPlaybackAllowed", - ).forEach { (fingerprint, integrationsMethod) -> + ).forEach { (fingerprint, extensionsMethod) -> fingerprint.methodOrThrow().apply { findInstructionIndicesReversedOrThrow(Opcode.RETURN).forEach { index -> val register = getInstruction(index).registerA @@ -47,7 +48,7 @@ val backgroundPlaybackPatch = bytecodePatch( addInstructionsAtControlFlowLabel( index, """ - invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR->$integrationsMethod(Z)Z + invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR->$extensionsMethod(Z)Z move-result v$register """, ) @@ -68,7 +69,17 @@ val backgroundPlaybackPatch = bytecodePatch( } // Force allowing background play for Shorts. - shortsBackgroundPlaybackFeatureFlagFingerprint.methodOrThrow().returnEarly(true) + shortsBackgroundPlaybackFeatureFlagFingerprint.methodOrThrow().addInstructionsWithLabels( + 0, + """ + invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR->isBackgroundShortsPlaybackAllowed()Z + move-result v0 + if-eqz v0, :disabled + return v0 + :disabled + nop + """ + ) // Force allowing background play for videos labeled for kids. kidsBackgroundPlaybackPolicyControllerFingerprint.methodOrThrow(