I am using AVAudioRecorder in my mac app. In my .m file I declare
@interface RecordViewController ()
{
AVAudioRecorder *audioRecorder;
...
}
@end
further down I then alloc init the object like so:
audioRecorder = [[[AVAudioRecorder alloc] initWithURL:soundFileURL settings:recorderSettings error:&error] retain];
...
[audioRecorder prepareToRecord];
...
[audioRecorder record];
I can see that the file gets created, but it only has 4KB. I do not get an error but when I test if [audioRecorder isRecording] I can see that [audioRecorder is no longer recording. I am assuming that the object got released, even though I am not using ARC and the dealloc method was not called.
I had a similar problem with the AVAudioPlayer but the additional retain] appended to the alloc init solved that.
What am I doing wrong?
Thanks
UPDATE 1:
I have even tried to do the following (all in the same method):
[audioRecorder record];
NSLog(@"recording is ... %d", [audioRecorder isRecording]);
and the result is 0.
???
Do I have to use self ? or lazily instantiate audioRecorder?
UPDATE 2:
I recreated the project – called it TEST and copied the source code from my old project. Now it works?!?! Go figure. The source codes are line for line the same. Is this a known problem with XCode?
First of all, based on your comment, if you can still access the instance means that your object isn’t dealloc.
AVAudioRecorder provide a delegate (AVAudioRecorderDelegate) have you tried to use the delegate for log if the recording is successfully or you get some error?
Particularly the method
audioRecorderEncodeErrorDidOccur:error:should give you some error if occurred while recording.BTW the additions
retain]is not need because whitallocinityou’ve got the ownership of the object and you should release.