如何在耳机插入时录制Karoke?

时间:2016-11-14 10:29:31

标签: ios swift xcode avaudioplayer headphones

我想制作一个卡拉OK应用程序,一切都很完美,没有耳机插件。 [.MixWithOthers,.DefaultToSpeaker])

我想将其设置为[.MixWithOthers,.DefaultToHeadPhones])

但没有任何类似的功能。但是当耳机插入时,混音录音无法正常工作。 这是我的示例代码: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)
    }
}

0 个答案:

没有答案