0

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)
    }
}
HariKarthick
  • 1,369
  • 1
  • 19
  • 47
  • Please post relevant code. – shallowThought Nov 14 '16 at 10:49
  • https://github.com/genedelisa/AVFoundationRecorder/blob/master/AVFoundation%20Recorder/RecorderViewController.swift – HariKarthick Nov 14 '16 at 12:03
  • Can not find `.DefaultToHeadPhones`in there. – shallowThought Nov 14 '16 at 12:19
  • There is no function like this:DefaultToHeadPhones.. So i want to know how to record voice and music while headphone is plugged in – HariKarthick Nov 14 '16 at 12:25
  • I meant `.DefaultToSpeaker`. Copy & paste error. How I understood, you are setting the audio sessions category to .DefaultToSpeaker, but it does not work for you. So I was lookong for your setup in your code and could not find it. Maybe post relevant code in your question. – shallowThought Nov 14 '16 at 12:28
  • try session.setCategory(AVAudioSessionCategoryPlayAndRecord, withOptions:AVAudioSessionCategoryOptions.DefaultToSpeaker) – HariKarthick Nov 14 '16 at 12:30
  • I used this same code for my app.If u don't mind can you check this link : https://github.com/genedelisa/AVFoundationRecorder/blob/master/AVFoundation%20Recorder/RecorderViewController.swift – HariKarthick Nov 14 '16 at 12:42

0 Answers0