我正在尝试使用以下代码为启动和停止按钮创建一个简单的iphone录音机。
编译工作正常,但是当我尝试调试程序并按下开始按钮时,我得到线程1:跟踪,在其中显示“error: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!";
}
答案 0 :(得分:0)
我遇到了类似的问题。我自己在[AVAudioSession sharedInstance]上获得了一个异常断点,在控制台窗口中没有异常。但是,我在控制台输出中得到了这个:
<com.apple.main-thread> AddPropertyListenerImp posting message to kill mediaserverd (0)
我也在我的应用程序中录制,但是当我的录制失灵并且重新启动应用程序时,我正在收到此消息。所以这是应用程序的一个新的运行 - 但很明显,由于之前发生的事情,设备已陷入问题状态。
希望有所帮助 - 我知道这不是一个解决方案的直接答案,但我想更多地说明。