1

iOS アプリでオーディオを録音するために使用される AVAudioRecorder に奇妙な状況があります。まれに、オーディオ セッションの録音が開始されない iPad2 デバイスをいくつか見つけました。iOS アプリのコードは、他のすべてのタイプの iPod Touch、iPhone、および iPad、およびシミュレーターで正常に記録されます。ごく一部のケースで記録できないようです。なぜこれが起こっているのか誰にも分かりますか?

コーディング情報はこちら。


私の .h ファイルには、AVAudioRecorder が設定されています...

RVC.h

@interface RVC : UIViewController <AVAudioRecorderDelegate, AVAudioPlayerDelegate>{
    AVAudioRecorder *audioRecorder;
}
@property (nonatomic, retain) AVAudioRecorder *audioRecorder;

RVC.m

@implementation RVC
@synthesize audioRecorder;

// Set up the file path and name, where the path is to the temporary directory
soundFile = [NSURL fileURLWithPath:[tempDir stringByAppendingFormat:@"theSoundFile.m4a"]];

// Set up the settings for the recording
soundSetting = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat: 44100.0],AVSampleRateKey,
      [NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
      [NSNumber numberWithInt: 2], AVNumberOfChannelsKey,
      [NSNumber numberWithInt: AVAudioQualityHigh], AVEncoderAudioQualityKey, nil];

// Make the AVAudioRecorder with the filename and the sound settings.
self.audioRecorder = [[AVAudioRecorder alloc] initWithURL:soundFile settings:soundSetting error:&error];

// Check to make sure the iOS device has audio hardware that can make a recording
BOOL audioHWAvailable = [[AVAudioSession sharedInstance] inputIsAvailable];
if (! audioHWAvailable) {
   NSLog(@"No audio hardware is available.");
   return;
}

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];

// Make sure any output sound is played through the speakers.
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);

[[AVAudioSession sharedInstance] setActive:YES error:nil];

// If the audiorecorder is properly set up, then start recording.
if (audioRecorder) {
    [audioRecorder prepareToRecord];
    // Start the recording
    isRecording = [audioRecorder record];
}
else {
    isRecording = FALSE;
    NSLog(@"The audio recorder was not properly set up.");
}

if (isRecording) {
    // The AVAudioSession is recording.
}
else {
    // The AVAudioSession did not start so make some kind of log file.
    NSLog(@"The recording was not started properly.");
    // This is where THE PROBLEM SHOWS UP where it is having trouble with some versions of the iPad2, which I can not replicate in the simulators.
    return;
}
4

1 に答える 1

1

errorinit 呼び出しでを渡しています。

self.audioRecorder = [[AVAudioRecorder alloc] initWithURL:soundFile settings:soundSetting error:&error];

しかし、あなたはそれを読んでいません。失敗した場合、ここでエラーが発生し、audioRecorder がnil.

于 2012-07-15T14:43:53.973 に答える