Reputation: 333
I'am using an AVPlayerViewController for playing video in streaming.
When I launch Airplay on the AVPlayerViewController on the Apple TV and put the app in background or if I lock the device, the video paused on the Apple TV.
I verify that like in this post [https://developer.apple.com/library/archive/qa/qa1668/_index.html#//apple_ref/doc/uid/DTS40010209][1]
I had check the background audio, airplay mode My audio Session is started and active in AVAudioSessionCategoryPlayback My AVPlayer is in playing mode when I go in background or if I lock the device
I read the 'Special Considerations for Video Media' paragraph of this post [https://developer.apple.com/library/archive/qa/qa1668/_index.html#//apple_ref/doc/uid/DTS40010209][1], but they don't spoke about the AVPlayerViewController.
I understand that video is not one of the possible background mode capabilities but Airplay is.
So do you have any way to have the video stream audio/image playing with the app' in background or device locked using the AVPlayerViewController ?
Thank you in advance for your advices or any technical link that I would have missed.
Upvotes: 3
Views: 2596
Reputation: 3676
Xcode 13
All I had to do was enable background mode Audio, Airplay, and Picture in Picture
. To do this, just select your target, add background modes and tick the checkbox for Audio, Airplay, and Picture in Picture.
Then set the category of the AV session. I did this just before the video played.
let audioSession = AVAudioSession.sharedInstance()
do {
try audioSession.setCategory(.playback)
} catch {
print("Setting category to AVAudioSessionCategoryPlayback failed.")
}
It then supported playing video over airplay while the device is locked. I was using an AVPlayerViewController
.
Upvotes: 2