【问题标题】:Operation could not be completed. AVAudioRecorder iphone SDK无法完成操作。 AVAudioRecorder iphone SDK
【发布时间】:2011-01-27 20:25:33
【问题描述】:

我正在尝试使用 iphone 麦克风进行录音:这是我的代码:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

// the path to write file
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:@"testing.mp3"];




NSURL *url = [NSURL fileURLWithPath:appFile isDirectory:NO];

NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
                          [NSNumber numberWithFloat: 44100.0],                 AVSampleRateKey,
                          [NSNumber numberWithInt: kAudioFormatMPEGLayer3], AVFormatIDKey,
                          [NSNumber numberWithInt: 1],                         AVNumberOfChannelsKey,
                          [NSNumber numberWithInt: AVAudioQualityLow],         AVEncoderAudioQualityKey,
                          nil];

NSError *error;

recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];

if ([recorder prepareToRecord] == YES){
    [recorder record];
}else {
    int errorCode = CFSwapInt32HostToBig ([error code]); 
    NSLog(@"Error: %@ [%4.4s])" , [error localizedDescription], (char*)&errorCode); 

}

NSLog(@"BOOL = %d", (int)recorder.recording);

这是我得到的错误:

Operation could not be completed. (OSStatus error 1718449215.)

我无法弄清楚为什么这不起作用,因为我从网站上获得了很多代码。

乔纳森

【问题讨论】:

  • 由于某种原因它没有初始化。正如if (recorder) { NSLog:@"Yes"; } 所做的那样,不会在日志中写入“是”。

标签: iphone objective-c iphone-sdk-3.0 ios-simulator


【解决方案1】:

您的问题是 kAudioFormatMPEGLayer3

很遗憾,您无法在 iPhone 上将声音编码为 mp3 格式。目前压缩音频的最佳格式是 kAudioFormatAppleIMA4。 (是的,还有 kAudioFormatMPEG4AAC - 更好,但它仅适用于模拟器,但不适用于设备)。 另请注意,在其他系统上解码记录的 kAudioFormatAppleIMA4 文件可能会出现问题,例如windows,所以简单的lpcm格式对于小文件可能更方便。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2019-05-27
  • 1970-01-01
  • 2013-10-31
  • 2013-07-25
  • 1970-01-01
  • 1970-01-01
  • 2012-12-24
  • 1970-01-01
相关资源
最近更新 更多