2021年1月2日星期六

AVAudioSession option change does not take effect

My iOS app plays audio from a URL. Most of the time, I want this audio to not mix with other audio played on the device.

But sometimes, I do want to allow the audio to mix with other audio on the device.

When I initially start my audio, it works as desired; it does not mix with other audio on the device (i.e. playing music on Spotify will stop my audio from playing).

And when I call the following code, it successfully allows my audio to mix with others as desired:

    try! AVAudioSession.sharedInstance().setCategory(.playback, options: .mixWithOthers)  

However, when I try to change it back to not mix with others it does not work; other audio from the device is playing along with my audio. Even though I am calling:

    try! AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback)  

Any idea why I cannot change the AVAudioSession back to not mixing with others?

https://stackoverflow.com/questions/65546276/avaudiosession-option-change-does-not-take-effect January 03, 2021 at 11:04AM

没有评论:

发表评论