0

我正在尝试使用下面的代码为 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!";
}
4

1 回答 1

0

我遇到了类似的问题。我自己在 [AVAudioSession sharedInstance] 上获得了一个异常断点,在控制台窗口中也没有异常。但是,我确实在控制台输出中得到了这个:

<com.apple.main-thread> AddPropertyListenerImp posting message to kill mediaserverd (0)

我也在我的应用程序中录制,但是当我的录制出现故障并重新启动应用程序时,我得到了这个。所以这是应用程序的全新运行 - 但显然由于之前发生的事情,该设备已进入有问题的状态。

希望有所帮助-我知道这不是解决方案的直接答案,但我想阐明更多信息。

于 2013-02-15T15:53:22.547 回答