Skip to content

Commit ca4072e

Browse files
authored
[video_player_avfoundation] Route video over AirPlay (flutter#12490)
`usesExternalPlaybackWhileExternalScreenIsActive` defaults to NO, so an AVPlayer keeps the picture on the device whenever an external screen is active. Selecting an AirPlay route therefore moved only the audio, while the receiver showed a mirrored copy of the screen rather than playing the stream itself. `allowsExternalPlayback` already defaults to YES, so the two together were incoherent: external playback was permitted but never used. AVKit's own AVPlayerViewController routes to AirPlay out of the box; this brings the plugin in line with it. Verified on an Apple TV from iOS 26.6. Fixes: flutter#191227 ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 866678c commit ca4072e

4 files changed

Lines changed: 41 additions & 1 deletion

File tree

‎packages/video_player/video_player_avfoundation/CHANGELOG.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 2.12.0
2+
3+
* Routes video over AirPlay when an external screen is active, by setting
4+
`usesExternalPlaybackWhileExternalScreenIsActive` on the `AVPlayer`. Selecting
5+
an AirPlay route previously moved only the audio, leaving the video on the
6+
device while the receiver showed a mirrored screen.
7+
18
## 2.11.1
29

310
* Updates pigeon dev_dependency to ^27.3.2 for analyzer 14 compatibility.

‎packages/video_player/video_player_avfoundation/darwin/RunnerTests/VideoPlayerTests.swift‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,23 @@ private let hlsAudioTestURI =
396396
#expect(player.player.preventsDisplaySleepDuringVideoPlayback == true)
397397
}
398398

399+
#if os(iOS)
400+
@Test func externalPlaybackIsEnabledForAirPlay() {
401+
let stubAVFactory = StubFVPAVFactory(player: AVPlayer())
402+
let player = FVPVideoPlayer(
403+
playerItem: StubPlayerItem(),
404+
avFactory: stubAVFactory,
405+
viewProvider: StubViewProvider())
406+
407+
// usesExternalPlaybackWhileExternalScreenIsActive defaults to NO, which
408+
// keeps the video on the device whenever an external screen is active. An
409+
// AirPlay route then moves only the audio, and the receiver shows a
410+
// mirrored screen rather than playing the stream itself.
411+
#expect(player.player.allowsExternalPlayback == true)
412+
#expect(player.player.usesExternalPlaybackWhileExternalScreenIsActive == true)
413+
}
414+
#endif
415+
399416
/// Sanity checks a video player playing the given URL with the actual AVPlayer. This is essentially
400417
/// a mini integration test of the player component.
401418
///

‎packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation_objc/FVPVideoPlayer.m‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,22 @@ - (instancetype)initWithPlayerItem:(NSObject<FVPAVPlayerItem> *)item
145145
_player = [avFactory playerWithPlayerItem:item];
146146
_player.actionAtItemEnd = AVPlayerActionAtItemEndNone;
147147

148+
#if TARGET_OS_IOS
149+
// Allow the video to follow an AirPlay route to an external device.
150+
//
151+
// allowsExternalPlayback already defaults to YES, but
152+
// usesExternalPlaybackWhileExternalScreenIsActive defaults to NO, so the
153+
// player deliberately keeps the picture on the device whenever an external
154+
// screen is active. The result is that selecting an AirPlay route changes the
155+
// audio route while the video stays on the phone and the TV only receives a
156+
// mirrored copy of the screen.
157+
//
158+
// Verified on an Apple TV: with both set, the receiver plays the stream
159+
// itself and the local surface is released.
160+
_player.allowsExternalPlayback = YES;
161+
_player.usesExternalPlaybackWhileExternalScreenIsActive = YES;
162+
#endif
163+
148164
// Configure output. AVVideoColorPropertiesKey must be declared on the output settings (not on
149165
// pixel buffer attributes, where AVFoundation silently ignores it) so that HDR sources are
150166
// tone-mapped to BT.709 SDR for the Flutter texture.

‎packages/video_player/video_player_avfoundation/pubspec.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: video_player_avfoundation
22
description: iOS and macOS implementation of the video_player plugin.
33
repository: https://github.com/flutter/packages/tree/main/packages/video_player/video_player_avfoundation
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
5-
version: 2.11.1
5+
version: 2.12.0
66

77
environment:
88
sdk: ^3.10.0

0 commit comments

Comments
 (0)