lundi 3 août 2015

Hear recording voice and background track at the same time with ios swift? [on hold]

I am able to record entire audio stream including background track when head phone not plugged into device . But when headphone plugged into device, i want to hear my voice and background track same time from headphone. But i hear only background track. How can i do that?

this is my recording code.

var audioRecorder:AVAudioRecorder!


func record(){

    var audioSession:AVAudioSession = AVAudioSession.sharedInstance()
    audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord, error: nil)
    audioSession.setActive(true, error: nil)

    var documents: AnyObject = NSSearchPathForDirectoriesInDomains( NSSearchPathDirectory.DocumentDirectory,  NSSearchPathDomainMask.UserDomainMask, true)[0]
    var str =  documents.stringByAppendingPathComponent("recordTest.m4a")
    var url = NSURL.fileURLWithPath(str as String)

    var recordSettings = [AVFormatIDKey:kAudioFormatAppleIMA4,
        AVSampleRateKey:44100.0,
        AVNumberOfChannelsKey:2,AVEncoderBitRateKey:12800,
        AVLinearPCMBitDepthKey:16,
        AVEncoderAudioQualityKey:AVAudioQuality.Max.rawValue

    ]

    println("url : \(url)")
    var error: NSError?

    audioRecorder = AVAudioRecorder(URL:url, settings: recordSettings, error: &error)
    if let e = error {
        println(e.localizedDescription)
    } else {

        audioRecorder.record()
    }


}

Aucun commentaire:

Enregistrer un commentaire