I have an avassetwriter
capture session to record a video and 2 avplayerqueues
to playback the immediately recorded video and the other, to playback past saved videos.
My problem is the audio input does not use my bluetooth earphones, and performs playback and record via the iphone device inputs/outputs.
I did not implement any override to default to the speaker, understand I need to handle a route change via notification observer in the case of toggling between bluetooth and device, and also tried setting the AVAudioSession.sharedInstance()
.playbackAndRecording
category to .allowBluetooth
to no avail.
Any guidance would be appreciated as I have not come across an existing answer online..
let audioSession = AVAudioSession.sharedInstance()
//Executed right before playing avqueueplayer media
do {
try audioSession.setCategory(.playback)
try audioSession.setActive(true)
} catch {
fatalError("Error Setting Up Audio Session")
}
//Executed right after avqueueplayer finishes media
do {
try audioSession.setCategory(.recording, options: [.allowBluetooth])
try audioSession.setActive(true)
} catch {
fatalError("Error Setting Up Audio Session")
}