2016-06-28 207 views
0

我有一个应用程序,它应该记录音频时,我按下了一个按钮。 在我的ViewDidLoad我preapare录音机,问题是流'音频中断时,'self.audioRecorder.prepareToRecord()'行被调用。iOS流音频和记录音频

我的设置:

do { 
    recordingSession = AVAudioSession.sharedInstance() 
    try recordingSession.setCategory(AVAudioSessionCategoryRecord, withOptions: [.DuckOthers, .AllowBluetooth, .MixWithOthers]) 

    recordingSession.requestRecordPermission() { [unowned self] (allowed: Bool) -> Void in 
     dispatch_async(dispatch_get_main_queue()) { 
      do { 
       if allowed { 
        self.audioRecorder = try AVAudioRecorder(URL: self.tempAudioPath, settings: self.settings) 
        self.audioRecorder.delegate = self 
        self.audioRecorder.prepareToRecord() 
        //self.audioRecorder.record() 
       } else { 
        // failed to record! 
        print("No Access to Micro") 
       } 
      }catch{} 
     } 
    } 
} catch { 
    print (error) 
} 

是有办法preapare备案录音机,并继续在后台播放音频? (在录制音频时将其放在其上)

+1

在播放音频时录音涉及使用AudioUnits:https://developer.apple.com/library/ios/documentation/MusicAudio/Conceptual/AudioUnitHostingGuide_iOS/AudioUnitHostingFundamentals/AudioUnitHostingFundamentals.html – SArnab

回答