Fix: ensure audio session allows AirPlay routing during media playback

The audio session category options include .allowBluetoothA2DP for
certain playback types but omit .allowAirPlay, preventing proper
AirPlay audio routing during media playback. This adds .allowAirPlay
to the .play and .playWithPossiblePortOverride session types for
consistency with other wireless audio routing options.

Also explicitly sets allowsExternalPlayback = true on AVPlayer
instances in PlatformVideoContent and SystemVideoContent to document
external playback intent and prevent potential regressions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Esteve Castells 2026-04-09 13:48:26 +02:00
parent be6c32ef9c
commit 5314c6c4d4
3 changed files with 4 additions and 0 deletions

View file

@ -866,12 +866,14 @@ public final class ManagedAudioSessionImpl: NSObject, ManagedAudioSession {
if mixWithOthers {
options.insert(.mixWithOthers)
}
options.insert(.allowAirPlay)
case .ambient:
options.insert(.mixWithOthers)
case .playWithPossiblePortOverride:
if case .playAndRecord = nativeCategory {
options.insert(.allowBluetoothA2DP)
}
options.insert(.allowAirPlay)
case .voiceCall, .videoCall:
#if canImport(AlarmKit) //Xcode 26
options.insert(.allowBluetoothHFP)

View file

@ -186,6 +186,7 @@ private final class PlatformVideoContentNode: ASDisplayNode, UniversalVideoConte
self.imageNode = TransformImageNode()
let player = AVPlayer(playerItem: nil)
player.allowsExternalPlayback = true
self.player = player
self.playerNode = ASDisplayNode()

View file

@ -100,6 +100,7 @@ private final class SystemVideoContentNode: ASDisplayNode, UniversalVideoContent
self.playerItem = AVPlayerItem(url: URL(string: url)!)
let player = AVPlayer(playerItem: self.playerItem)
player.allowsExternalPlayback = true
self.player = player
self.playerNode = ASDisplayNode()