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,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<OneRegisterInstruction>(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(