ios - Can't stop audioRecorder -
here's part of code:
class audiorecordercontroller: uiviewcontroller, avaudiorecorderdelegate {
var audiorecorder: avaudiorecorder? func audiorecordingpath() -> nsurl { let filemanager = nsfilemanager() let documentsfolderurl = filemanager.urlfordirectory(.documentdirectory, indomain: .userdomainmask, appropriateforurl: nil, create: false, error: nil) return documentsfolderurl!.urlbyappendingpathcomponent("recording.m4a") } func audiorecordingsettings() -> nsdictionary {...} func startrecordingaudio() { var error: nserror? let audiorecordingurl = self.audiorecordingpath() audiorecorder = avaudiorecorder(url: audiorecordingurl, settings: audiorecordingsettings() [nsobject: anyobject], error: &error) if let recorder = audiorecorder { recorder.delegate = self if recorder.preparetorecord() && recorder.record() { println("capture succeed!") let delayinseconds = 5.0 let delayinnanoseconds = dispatch_time(dispatch_time_now, int64(delayinseconds * double(nsec_per_sec))) dispatch_after(delayinnanoseconds, dispatch_get_main_queue(), { [weak self] in self!.audiorecorder!.stop() //it breaks here. }) } } }
it printed "capture succeed" in console, crashed error "unexpectedly found nil while unwrapping optional value". what's problem last line of code?
have tried replacing
self!.audiorecorder!.stop()
with using unwrapped constant
recorder.stop()
Comments
Post a Comment