Background audio handling with iOS AVPlayer
Application developers often want to persist audio when iOS applications enter the background, such as when a device is locked or another application is used. By default, AVPlayer does not support this feature. To enable background audio functionality, update your application's Background Modes and configure the shared audio instance using AVAudioSession.Category.playback. Additionally, detach the player from the UI in SceneDelegate when entering the background and reattach it when returning to the foreground. While some developers have attempted to force AVPlayer to switch to an audio-only rendition of a video when no video is being shown, this approach has not been successful without potential drawbacks. Furthermore, enabling both picture-in-picture capabilities and playing audio when entering the background may cause issues with certain applications.
Company
Mux
Date published
May 27, 2021
Author(s)
Dylan Jhaveri
Word count
1389
Hacker News points
None found.
Language
English