I want to make a karaoke app and everything is perfect, without headphone plug-in. [.MixWithOthers, .DefaultToSpeaker])
I want to set it to [.MixWithOthers, .DefaultToHeadPhones])
but there is not any function like that. However mix recording not working when headphone plugged-in. It's my sample code: https://github.com/genedelisa/AVFoundationRecorder/blob/master/AVFoundation%20Recorder/RecorderViewController.swift
func setSessionPlayback() { let session:AVAudioSession = AVAudioSession.sharedInstance()
do {
try session.setCategory(AVAudioSessionCategoryPlayAndRecord)
} catch let error as NSError {
print("could not set session category")
print(error.localizedDescription)
}
do {
// try session.setActive(true)
} catch let error as NSError {
print("could not make session active")
print(error.localizedDescription)
}
}
func setSessionPlayAndRecord()
{
let session = AVAudioSession.sharedInstance()
do {
// var setCategoryErr: NSError? = nil
// var activationErr: NSError? = nil
//Set the general audio session category
try session.setCategory(AVAudioSessionCategoryPlayAndRecord)
var doChangeDefaultRoute: UInt32 = 1
do {
try session.setCategory(AVAudioSessionCategoryPlayAndRecord,
withOptions:AVAudioSessionCategoryOptions.DefaultToSpeaker)
}
catch let error {
}
//Activate the customized audio session
try session.setActive(true)
} catch let error as NSError {
print("could not set session category")
print(error.localizedDescription)
}
do {
// try session.setActive(true)
} catch let error as NSError {
print("could not make session active")
print(error.localizedDescription)
}
}