Using .mixWithOthers or . duckOthers when setting category of AVAudioSession.sharedInstance gives error in WatchOS10

Hi,

I have an audio playing Watch app that uses the shared AVAudioSession to play audio.

Until WatchOS10 it was working fine, with the session configured as follows:

try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback, mode: .default, policy: .longFormAudio, options: [.mixWithOthers])

But in WatchOS10, the following error is thrown

The operation couldn’t be completed. (OSStatus error -50.)

Using a category of [.duckOthers] produces the same error.

Setting the category options to [] does not throw the error, but now the audio is not mixed with other system audio.

Anyone else having this problem, or have a solution?

Thanks Rich

Even with the options set to [] (which does not error), when I call

try AVAudioSession.sharedInstance().setActive(true)

It throws another error - Error Domain=NSOSStatusErrorDomain Code=561145203 "Session activation failed".

Thanks Rich

OSStatus error -50 means some of the arguments given to setCategory were incorrect. In this case, longFormAudio sessions are mutually exclusive, so that conflicts with the mixWithOthers and duckOthers options.

From the documentation page for longFormAudio, watchOS apps that use this policy "must activate their audio session using the activate(options:completionHandler:) method". So please use activate instead of setActive in watchOS when including the longFormAudio policy.

Many thanks for the reply.

So with longFormAudio, it can't now mix with other system audio, for instance Siri? This seems like a backward step.

I will try and see if it mixes anyway :-)

Thanks Rich

I've updated the code as follows and it all works fine. Interestingly even though I haven't specified to mixWithOthers, it still does.

Please note that for anyone trying to find options to set on the session.activate options parameter, there aren't any! All you can use is []

 if #available(watchOS 10.0, *) {
                try session.setCategory(AVAudioSession.Category.playback,
                                        mode: .default,
                                        policy: .longFormAudio,
                                        options: [])
                
                session.activate(options:[]){ success, error in
                    if (error != nil) {
                        print ("Error in activating audio session")
                    } else {
                        if success {
                            print ("Audio session successfully activated")
                        } else {
                            print ("Audio session not activated")
                        }
                    }
                }
Using .mixWithOthers or . duckOthers when setting category of AVAudioSession.sharedInstance gives error in WatchOS10
 
 
Q