Prepare ToRecord crashing

I read about AVaudioRecorder from the Apple documentation http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/MultimediaPG/UsingAudio/UsingAudio.html#//apple_ref/doc/uid/TP40009767-CH2-SW6

and I found a function in which records are recorded. but my code falls on

[soundRecorder prepareToRecord]; 

i searched so much googled. But I did not find a solution. I also found some other source codes. But they also have the same problem (crashing on prepareToRecord). can anyone help me ...

my hare IBAction

- (IBAction) recordOrStop: (id) sender {

if (recording) {

    [soundRecorder stop];
    recording = NO;
    self.soundRecorder = nil;

    [recordOrStopButton setTitle: @"Record" forState:
     UIControlStateNormal];
    [recordOrStopButton setTitle: @"Record" forState:
     UIControlStateHighlighted];
    [[AVAudioSession sharedInstance] setActive: NO error: nil];

} else {

    [[AVAudioSession sharedInstance]
     setCategory: AVAudioSessionCategoryRecord
     error: nil];

    NSDictionary *recordSettings =
    [[NSDictionary alloc] initWithObjectsAndKeys:
     [NSNumber numberWithFloat: 44100.0], AVSampleRateKey,
     [NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
     [NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
     [NSNumber numberWithInt: AVAudioQualityMax],
     AVEncoderAudioQualityKey,
     nil];
    AVAudioRecorder *newRecorder =
    [[AVAudioRecorder alloc] initWithURL: soundFileURL
                                settings: recordSettings
                                   error: nil];



    self.soundRecorder = newRecorder;

    soundRecorder.delegate = self;
    [soundRecorder prepareToRecord];
    [soundRecorder record];
    [recordOrStopButton setTitle: @"Stop" forState: UIControlStateNormal];
    [recordOrStopButton setTitle: @"Stop" forState: UIControlStateHighlighted];

    recording = YES;
}

}

My .h file

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <CoreAudio/CoreAudioTypes.h>
#import "MBProgressHUD.h"

@interface LyricsController : UIViewController<AVAudioSessionDelegate,AVAudioRecorderDelegate, MBProgressHUDDelegate>{

IBOutlet UITextView *LyricsView;
MBProgressHUD *HUD;
AVAudioRecorder * soundRecorder;
NSURL *soundFileURL;  

BOOL recording;
BOOL playing;

__weak IBOutlet UIButton *recordOrStopButton;
}@property(strong,nonatomic)NSURL *soundFileURL;
@property(nonatomic,strong)AVAudioRecorder * soundRecorder;
+3
source share
2 answers

, . , , prepareTorecord , . xcode, .

+3

:

"" "Objective-C " AudioToolbox ++. .

:

"AVAudioPlayer " - . , . , , .

+1

All Articles