fix(YouTube - Remove background playback restriction): Play/Pause button not working in PiP mode https://github.com/inotia00/ReVanced_Extended/issues/2764

This commit is contained in:
inotia00 2025-02-07 14:46:49 +09:00
parent e97f37e224
commit 6f1fc6116b
2 changed files with 29 additions and 4 deletions

View File

@ -1,10 +1,14 @@
package app.revanced.extension.youtube.patches.misc; 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.settings.Settings;
import app.revanced.extension.youtube.shared.PlayerType;
import app.revanced.extension.youtube.shared.ShortsPlayerState; import app.revanced.extension.youtube.shared.ShortsPlayerState;
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class BackgroundPlaybackPatch { public class BackgroundPlaybackPatch {
private static final BooleanSetting DISABLE_SHORTS_BACKGROUND_PLAYBACK =
Settings.DISABLE_SHORTS_BACKGROUND_PLAYBACK;
/** /**
* Injection point. * Injection point.
@ -14,11 +18,21 @@ public class BackgroundPlaybackPatch {
return ShortsPlayerState.getCurrent().isClosed(); return ShortsPlayerState.getCurrent().isClosed();
} }
/**
* Injection point.
*/
public static boolean isBackgroundShortsPlaybackAllowed() {
if (PlayerType.getCurrent().isNoneHiddenOrMinimized()) {
return !DISABLE_SHORTS_BACKGROUND_PLAYBACK.get();
}
return false;
}
/** /**
* Injection point. * Injection point.
*/ */
public static boolean isBackgroundShortsPlaybackAllowed(boolean original) { public static boolean isBackgroundShortsPlaybackAllowed(boolean original) {
return !Settings.DISABLE_SHORTS_BACKGROUND_PLAYBACK.get(); return !DISABLE_SHORTS_BACKGROUND_PLAYBACK.get();
} }
} }

View File

@ -1,5 +1,6 @@
package app.revanced.patches.youtube.misc.backgroundplayback 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.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.instructions import app.revanced.patcher.extensions.InstructionExtensions.instructions
import app.revanced.patcher.patch.bytecodePatch import app.revanced.patcher.patch.bytecodePatch
@ -39,7 +40,7 @@ val backgroundPlaybackPatch = bytecodePatch(
arrayOf( arrayOf(
backgroundPlaybackManagerFingerprint to "isBackgroundPlaybackAllowed", backgroundPlaybackManagerFingerprint to "isBackgroundPlaybackAllowed",
backgroundPlaybackManagerShortsFingerprint to "isBackgroundShortsPlaybackAllowed", backgroundPlaybackManagerShortsFingerprint to "isBackgroundShortsPlaybackAllowed",
).forEach { (fingerprint, integrationsMethod) -> ).forEach { (fingerprint, extensionsMethod) ->
fingerprint.methodOrThrow().apply { fingerprint.methodOrThrow().apply {
findInstructionIndicesReversedOrThrow(Opcode.RETURN).forEach { index -> findInstructionIndicesReversedOrThrow(Opcode.RETURN).forEach { index ->
val register = getInstruction<OneRegisterInstruction>(index).registerA val register = getInstruction<OneRegisterInstruction>(index).registerA
@ -47,7 +48,7 @@ val backgroundPlaybackPatch = bytecodePatch(
addInstructionsAtControlFlowLabel( addInstructionsAtControlFlowLabel(
index, 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 move-result v$register
""", """,
) )
@ -68,7 +69,17 @@ val backgroundPlaybackPatch = bytecodePatch(
} }
// Force allowing background play for Shorts. // 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. // Force allowing background play for videos labeled for kids.
kidsBackgroundPlaybackPolicyControllerFingerprint.methodOrThrow( kidsBackgroundPlaybackPolicyControllerFingerprint.methodOrThrow(