Home / Companies / Mux / Blog / Post Details
Content Deep Dive

Background audio handling with iOS AVPlayer

Blog post from Mux

Post Details
Company
Mux
Date Published
Author
Dylan Jhaveri
Word Count
1,389
Language
English
Hacker News Points
-
Summary

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.