2012-07-15 3 views
1

iOS 앱에 오디오를 녹음하는 데 AVAudioRecorder를 사용하는 이상한 상황이 있습니다. 오디오 세션에서 녹음이 시작되지 않는 일부 드문 iPad2 장치를 발견했습니다. iOS 앱 코드는 다른 모든 유형의 iPod Touch, iPhone 및 iPad뿐만 아니라 시뮬레이터에서도 잘 기록됩니다. 극소수의 경우에만 기록 할 수없는 것 같습니다. 왜 이런 일이 일어날 지 아는 사람이 있습니까?iOS 하드웨어가 특정 iOS 하드웨어에서 시작되지 않음

다음은 코딩 정보입니다. 내 .H 파일에서


나는

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; 
} 

답변

1

... AVAudioRecorder가 설정 한 초기화 호출에서 error을 전달 :

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

당신은 결코 그것을 읽지 않습니다. 나는 실패한 경우에 여기에서 오류가 발생하여 audioRecorder가 nil이 될 것입니다.