AudioRecorder to set maximum recording time iOS swift
Solution:
AVAudioRecorder did not had any maximum time for recording.You can achieve that by using Timer function.
var recorder: AVAudioRecorder!
var player:AVAudioPlayer!
var audioTime:Timer!
var timeSeconds:Double!
var isRecording:Bool!
declare those variables above the class.
In viewwillappear add the below code
isRecording = false
//record function
@IBAction func didTapOnRecord(_ sender: Any) {
if (isRecording == false) {
isRecording = true
audioTime = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(Stoptimer(RecordTime:)), userInfo: nil, repeats: true)
} else {
isRecording = false
audioTime.invalidate()
recorder?.stop()
}
}
// MARK: - Timer for maximumrecording
func Stoptimer(RecordTime:Double) {
timeSeconds = timeSeconds+audioTime.timeInterval
if timeSeconds == maxAudioTimeSeconds {
showAlert(msg: "Max audio Limit reached", controller: self)
self.didTapOnRecord(self)
}
}
Comments
Post a Comment