Reputation: 145
I am trying to create audio
record
, pause
and resume
record with help of AVFoundation
Framework. here, I have done record and stop using single button
but I want to do single button handle record, pause and resume three functionality. How to do that?
@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
}
}
}
Upvotes: 1
Views: 1850
Reputation: 217
@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
}
}
}
Try this
Upvotes: 2