【问题标题】:Trying to use AVAudioRecorder, exception when debugging尝试使用AVAudioRecorder,调试时出现异常
【发布时间】:2012-09-10 05:14:19
【问题描述】:

我正在尝试使用下面的代码为 iphone 创建一个带有开始和停止按钮的简单录音机。

编译工作正常,但是当我尝试调试程序并按下开始按钮时,我得到 Thread 1: Trace,在它显示“错误: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!";
}

【问题讨论】:

  • 如果您希望我们帮助消除您的异常,最好先告诉我们您有什么异常?

标签: iphone objective-c xcode ios5 avaudiorecorder


【解决方案1】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-13
    • 1970-01-01
    • 2013-11-16
    • 1970-01-01
    • 2022-01-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多