@@ -3,15 +3,19 @@ package app.revanced.patches.youtube.utils.fix.client
33import app.revanced.patcher.data.BytecodeContext
44import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
55import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
6+ import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
67import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
78import app.revanced.patcher.extensions.InstructionExtensions.getInstructions
89import app.revanced.patcher.extensions.or
910import app.revanced.patcher.patch.PatchException
1011import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
12+ import app.revanced.patcher.util.smali.ExternalLabel
1113import app.revanced.patches.shared.fingerprints.CreatePlayerRequestBodyWithModelFingerprint
1214import app.revanced.patches.shared.fingerprints.CreatePlayerRequestBodyWithModelFingerprint.indexOfModelInstruction
15+ import app.revanced.patches.youtube.misc.backgroundplayback.BackgroundPlaybackPatch
1316import app.revanced.patches.youtube.utils.compatibility.Constants
1417import app.revanced.patches.youtube.utils.fingerprints.PlaybackRateBottomSheetBuilderFingerprint
18+ import app.revanced.patches.youtube.utils.fix.client.fingerprints.BackgroundPlaybackPlayerResponseFingerprint
1519import app.revanced.patches.youtube.utils.fix.client.fingerprints.BuildInitPlaybackRequestFingerprint
1620import app.revanced.patches.youtube.utils.fix.client.fingerprints.BuildPlayerRequestURIFingerprint
1721import app.revanced.patches.youtube.utils.fix.client.fingerprints.CreatePlaybackSpeedMenuItemFingerprint
@@ -24,6 +28,7 @@ import app.revanced.patches.youtube.utils.fix.client.fingerprints.SetPlayerReque
2428import app.revanced.patches.youtube.utils.fix.client.fingerprints.UserAgentHeaderBuilderFingerprint
2529import app.revanced.patches.youtube.utils.integrations.Constants.MISC_PATH
2630import app.revanced.patches.youtube.utils.integrations.Constants.PATCH_STATUS_CLASS_DESCRIPTOR
31+ import app.revanced.patches.youtube.utils.playertype.PlayerTypeHookPatch
2732import app.revanced.patches.youtube.utils.settings.SettingsPatch
2833import app.revanced.patches.youtube.utils.storyboard.StoryboardHookPatch
2934import app.revanced.patches.youtube.video.information.VideoInformationPatch
@@ -50,6 +55,10 @@ object SpoofClientPatch : BaseBytecodePatch(
5055 name = " Spoof client" ,
5156 description = " Adds options to spoof the client to allow video playback." ,
5257 dependencies = setOf(
58+ // Required to fix background playback issue of live stream on iOS client.
59+ BackgroundPlaybackPatch ::class,
60+ PlayerTypeHookPatch ::class,
61+
5362 PlayerResponseMethodHookPatch ::class,
5463 SettingsPatch ::class,
5564 VideoInformationPatch ::class,
@@ -67,6 +76,9 @@ object SpoofClientPatch : BaseBytecodePatch(
6776 CreatePlayerRequestBodyWithVersionReleaseFingerprint ,
6877 UserAgentHeaderBuilderFingerprint ,
6978
79+ // Background playback in live stream.
80+ BackgroundPlaybackPlayerResponseFingerprint ,
81+
7082 // Player gesture config.
7183 PlayerGestureConfigSyntheticFingerprint ,
7284
@@ -379,6 +391,30 @@ object SpoofClientPatch : BaseBytecodePatch(
379391
380392 // endregion
381393
394+ // region fix background playback in live stream, if spoofing to iOS
395+
396+ /* *
397+ * If the return value of this method is true, background playback is always enabled.
398+ *
399+ * If [BackgroundPlaybackPatch] is excluded, there may be unintended behavior.
400+ * Therefore, [BackgroundPlaybackPatch] must be included.
401+ *
402+ * Also, [PlayerTypeHookPatch] is required to disable background playback in Shorts.
403+ */
404+ BackgroundPlaybackPlayerResponseFingerprint .resultOrThrow().mutableMethod.apply {
405+ addInstructionsWithLabels(
406+ 0 , """
407+ invoke-static { }, $INTEGRATIONS_CLASS_DESCRIPTOR ->forceEnableBackgroundPlayback()Z
408+ move-result v0
409+ if-eqz v0, :disabled
410+ const/4 v0, 0x1
411+ return v0
412+ """ , ExternalLabel (" disabled" , getInstruction(0 ))
413+ )
414+ }
415+
416+ // endregion
417+
382418 // region append spoof info.
383419
384420 NerdsStatsVideoFormatBuilderFingerprint .resultOrThrow().mutableMethod.apply {
0 commit comments