I have 2 instances of AVAudioPlayer
. One for notification sounds and one for music.
var soundPlayer: AVAudioPlayer?
var musicPlayer: AVAudioPlayer?
When the notification sound plays it should be able to .mixWithOthers
. This allows the notification to not interrupt another app playing music or video.
try AVAudioSession.sharedInstance().setCategory(.playback, options: [.mixWithOthers])
try AVAudioSession.sharedInstance().setActive(true)
However, if the user decides to play music via my app, then it should NOT .mixWithOthers
as seen here:
try AVAudioSession.sharedInstance().setCategory(.playback)
try AVAudioSession.sharedInstance().setActive(true)
The issue arises that AVAudioSession.sharedInstance()
is a singleton and it seems I can only have one setting for my entire app, not per AVAudioPlayer
using that method. And that the latest change to .sharedInstance()
updates both players.
Is there a way to set different categories setCategory
per player AVAudioPlayer
?