如果录制音频,声音无法播放?

时间:2017-01-20 12:08:33

标签: ios swift avfoundation

我有一个应用程序,每x秒发出一次声音。如果我正在录制音频,它会停止播放噪音,即使我能看到日志中触发的噪音/

相关代码:

import AVFoundation

-

var audioRecorder:AVAudioRecorder!

let session = AVAudioSession.sharedInstance()

-

override func viewDidLoad() {
    super.viewDidLoad()

    do {
        try! session.setCategory(AVAudioSessionCategoryPlayAndRecord, with: .defaultToSpeaker)
    }
}

func startRecording() {


    let df = DateFormatter()
    df.dateFormat = "y-MM-dd H:m"

    let fileName = "\(df.string(from: time)).wav"
    let path = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(fileName)

    audioRecorder = try! AVAudioRecorder(url: path, settings: [:])

    audioRecorder.isMeteringEnabled = true
    audioRecorder.prepareToRecord()
    audioRecorder.record()
}

播放声音的代码:

let systemSoundID: SystemSoundID = 1016 //random sound id
AudioServicesPlaySystemSound(systemSoundID)

有什么想法吗?

由于

0 个答案:

没有答案