Unknown selected data source for Port Speaker (type: Speaker)?

The message Unknown selected data source for Port Speaker seems to be a problem with iOS 12. Apparently it's some warning that appears even if the code is working. Perhaps Apple will fix this soon, so maybe for now you can ignore this warning and once they find a solution you will be able to silence it.

Source: AVAudioSession errors in iOS 12

As for the background music playing on silent mode, it's because of the AVAudioSessionCategory you selected. According to AVAudioSessionCategoryPlayback documentation (source):

When using this category, your app audio continues with the Silent switch set to silent or when the screen locks.

Depending on the style of your app, maybe you could use AVAudioSessionCategorySoloAmbient (source):

Your audio is silenced by screen locking and by the Silent switch (called the Ring/Silent switch on iPhone).

Or maybe AVAudioSessionCategoryAmbient (source):

This category is also appropriate for “play along” style apps, such as a virtual piano that a user plays while the Music app is playing. When you use this category, audio from other apps mixes with your audio. Your audio is silenced by screen locking and by the Silent switch (called the Ring/Silent switch on iPhone).


From Swift 4.2, I originally had it set up like this:

try AVAudioSession.sharedInstance().setCategory(.playAndRecord, mode: .default, options: [])

I didn't actually need recording capabilities, so I changed it to

try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: [])

This removed the error (and was the only thing I could do to get the error gone). However, if you need recording capabilities as well, obviously this won't work.

Tags:

Audio

Xcode

Swift