0
Audiorecorder 클래스를 Objective C에서 Swift로 다시 작성하기로 결정했습니다. Objective C
녹음에서 작동하지만 Swift
AVAudioRecorderDelegate
대리자 메서드가 호출되지 않으면 레코더가 성공적으로 시작됩니다.AVAudioRecorder 대리인이 Swift에 지정되지 않았습니다.
어떻게 해결할 수 있습니까?
self.audioRecorder?.stop
stop
메서드 호출되지 않습니다 :
class VoiceRecorder: NSObject, AVAudioPlayerDelegate, AVAudioRecorderDelegate {
var audioRecorder: AVAudioRecorder!
var audioPlayer: AVAudioPlayer?
override init() {
super.init()
var error: NSError?
let audioRecordingURL = self.audioRecordingPath()
audioRecorder = AVAudioRecorder(URL: audioRecordingURL,
settings: self.audioRecordingSettings(),
error: &error)
audioRecorder.meteringEnabled = true
/* Prepare the recorder and then start the recording */
audioRecorder.delegate = self
if audioRecorder.prepareToRecord(){
println("Successfully prepared for record.")
}
}
func audioRecorderDidFinishRecording(recorder: AVAudioRecorder!, successfully flag: Bool) {
println("stop")
if flag{
println("Successfully stopped the audio recording process")
if completionHandler != nil {
completionHandler(success: flag)
}
} else {
println("Stopping the audio recording failed")
}
}
}
func record(){
audioRecorder.record()
}
//UPD.
func stop(#completion:StopCompletionHandler){
self.completionHandler = completion
self.audioRecorder?.stop
}
코드가 정상적으로 보입니다. 왜 위임 메서드를 호출 할 것으로 기대합니까? 당신이 멈 추면 호출됩니다 -하지만 나는 멈추는 방법을 보지 못합니다 ... 어떻게 멈추 시렵니까? – matt
@matt 녹음을 마치려면 audioRecorder.stop()을 호출합니다. – Shmidt
그리고 어떻게됩니까? 로그에 전혀 없습니까? – matt