繁体   English   中英

为什么audioRecorderDidFinishRecording函数不起作用?

[英]Why does the audioRecorderDidFinishRecording function not work?

我正在开发一个iOS应用。 (iOS 11.2)当我按STOP时,我正在开发音频并转移到另一个视图。 但是以下功能不起作用。 (audioRecorderDidFinishRecording)

我尝试使用Google搜索,但是我在英语简短技能方面徘徊了很多。 请给很多建议。

class RecordSoundsViewController: UIViewController, AVAudioRecorderDelegate {
    var audioRecorder: AVAudioRecorder!

    @IBAction func stopRecording(_ sender: Any) {
        stopRecordingButton.isEnabled = false
        recordButton.isEnabled = true
        recordingLabel.text = "Tap to Record"
        audioRecorder.stop()
//        audioRecorder = nil
        let audioSession = AVAudioSession.sharedInstance()
        try! audioSession.setActive(false)
        // performSegue(withIdentifier: "stopRecording", sender: audioRecorder.url)
    }

    func audioRecorderDidFinishRecording(_ recorder: AVAudioRecorder, successfully flag: Bool) {
        if flag {
            performSegue(withIdentifier: "stopRecording", sender: audioRecorder.url)
        } else {
            print("recording was not successful")
        }
    }

查看您的代码,很可能您尚未为AVAudioRecorder分配委托。

无论您在初始化AVAudioRecorder实例的AVAudioRecorder ,在其下方尝试:

audioRecorder.delegate = self

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM