Skip to content

iOS Screen Mirroring Stops w/ Playback #2682

Description

@brianlenz

Describe the Bug
AVPlayerEngine.swift hard-codes allowsExternalPlayback = true and usesExternalPlaybackWhileExternalScreenIsActive = true (Apple's default for the latter is false). For audio-only apps this causes a regression: when the user is screen-mirroring to an Apple TV and starts playback, AVPlayer enters external playback mode, the Apple TV shows a black native player, and mirroring stops. Apple Music and other audio apps keep mirroring in this scenario.

Steps To Reproduce
Enable screen mirroring to an Apple TV from an RNTP app and start playing audio.

Options

  1. Set both flags to false to ensure screen mirroring always works. (FWIW, I have used a yarn patch to apply this fix for now.)
  2. Add an iosAllowsExternalPlayback option or similar (default false, or at minimum leave usesExternalPlaybackWhileExternalScreenIsActive at Apple's default) so audio-only apps can opt out.

Workaround

--- a/ios/player/AVPlayerEngine.swift
+++ b/ios/player/AVPlayerEngine.swift
@@ -219,10 +219,10 @@ class AVPlayerEngine: NSObject, PlayerEngine, AVPlayerItemMetadataOutputPushDele
       }
     }
 
-    avPlayer.allowsExternalPlayback = true
+    avPlayer.allowsExternalPlayback = false
     #if !os(macOS)
     // iOS-only API; the SPM test target builds PlayerCore for macOS.
-    avPlayer.usesExternalPlaybackWhileExternalScreenIsActive = true
+    avPlayer.usesExternalPlaybackWhileExternalScreenIsActive = false
     #endif
     observeTimeControlStatus()
     #if canImport(UIKit)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions