I'm using AVAudioSession to play videos with other apps playing sound background. But it doesn't work only at iPhone 13 pro(iOS 15.5). When I open my app while playing music on another app, the music stops.
These are the code I been using and trying it on different parts of my application.
DispatchQueue.global(qos: .userInitiated).async {
let audioSession = AVAudioSession.sharedInstance()
try? audioSession.setCategory(.playback, options: .mixWithOthers)
try? audioSession.setMode(.default)
try? audioSession.setActive(true)
}
DispatchQueue.global(qos: .userInitiated).async {
let audioSession = AVAudioSession.sharedInstance()
try? audioSession.setCategory(AVAudioSession.Category.ambient, options: [AVAudioSession.CategoryOptions.mixWithOthers])
try? audioSession.setActive(true)
}