我正试图在audio
框架的帮助下创建record
pause
,resume
和AVFoundation
记录。在这里,我已经完成了记录并停止使用单个button
,但是我想执行单个按钮处理记录,暂停和恢复三种功能。该怎么做?
@IBAction func record_click(_ sender: Any) {
// Record, Pause and Resume need to handle here
if let audioRecorder = self.audioRecorder {
if (audioRecorder.isRecording) {
audioRecorder.stop()
record_button.setImage(UIImage(named: "play.png"), for: UIControlState.normal)
save_bar_button.isEnabled = true
} else {
audioRecorder.record()
recordTimer = Timer.scheduledTimer(timeInterval: 0.1, target:self, selector:#selector(self.updateAudioMeter(timer:)), userInfo:nil, repeats:true)
record_button.setImage(UIImage(named: "pause.png"), for: UIControlState.normal)
save_bar_button.isEnabled = false
}
}
}
答案 0 :(得分:0)
@IBAction func record_click(_ sender: Any) {
// Record, Pause and Resume need to handle here
if let audioRecorder = self.audioRecorder {
if (audioRecorder.isRecording) {
audioRecorder.pauseRecording()
record_button.setImage(UIImage(named: "play.png"), for: UIControlState.normal)
save_bar_button.isEnabled = true
} else {
audioRecorder.resumeRecording()
recordTimer = Timer.scheduledTimer(timeInterval: 0.1, target:self, selector:#selector(self.updateAudioMeter(timer:)), userInfo:nil, repeats:true)
record_button.setImage(UIImage(named: "pause.png"), for: UIControlState.normal)
save_bar_button.isEnabled = false
}
}
}
尝试一下