How to use AVAudioSession, speakers to play background music, headphones to record?

`try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playAndRecord) try AVAudioSession.sharedInstance().overrideOutputAudioPort(.speaker)

That doesn't work. The background music still comes from the headphones.

How to use AVAudioSession, speakers to play background music, headphones to record?
 
 
Q