我正在尝试使用下面的代码为 iphone 创建一个带有开始和停止按钮的简单录音机。
编译工作正常,但是当我尝试调试程序并按下开始按钮时,我得到线程 1:跟踪,在它显示“错误:nil];”的行
甚至不确定如何开始弄清楚这意味着什么。顺便说一下,这将是第一次使用 Objective-c 和 xcode。
// Start recording or warn that already started
- (IBAction)startButton_clicked:(id)sender {
if (currentlyRecording == false)
{
// Sets recorder settings
[[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];
// Determine file name
NSString *fileDir = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/%@.wav", fileDir , GetCurrentTime()];
//debugText.text = [NSString stringWithFormat:@"%@", filePath]; // DEBUGGING
// Prepare recording
soundFileURL = [[NSURL alloc] initWithString:filePath];
AVAudioRecorder *newRecorder =
[[AVAudioRecorder alloc] initWithURL: soundFileURL
settings: recordSettings
error: nil];
[recordSettings release];
soundRecorder = newRecorder;
[newRecorder release];
// Record
[soundRecorder prepareToRecord];
[soundRecorder record];
currentlyRecording = true;
headLabel.text = @"Started";
}
// if currentlyrecording is already true
else headLabel.text = @"Already Started";
}
// stops recording or warns that already stopped
- (IBAction)stopButton_clicked:(id)sender {
if (currentlyRecording == true)
{
// Stop recording & clear vars
[soundRecorder stop];
soundRecorder = nil;
currentlyRecording = false;
headLabel.text = @"Stopped";
}
// if currentlyrecording is already false
else headLabel.text = @"It's not even on!";
}