iPhone用のテストアプリケーションを1つ作成しました。私は記録するために次のコードを書いた。しかし、それは動作していません。 録音できません
-(IBAction)start:(id)sender{
recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue:[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSetting setValue:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
[recordSetting setValue:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
soundsDirectoryPath = [documentsDirectory stringByAppendingPathComponent:@"Sounds"];
[[NSFileManager defaultManager] createFileAtPath:[NSString stringWithFormat:@"%@/Test.caf", soundsDirectoryPath] contents:nil attributes:nil];
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/Test.caf", soundsDirectoryPath]];
NSError *err = nil;
if([recorder isRecording])
{
[recorder stop];
recorder = nil;
}
recorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSetting error:&err];
[recorder setDelegate:self];
recorder.meteringEnabled = YES;
if(err){
NSLog(@"Error : %@", [err description]);
}
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
BOOL audioHWAvailable = audioSession.inputIsAvailable;
if (! audioHWAvailable) {
UIAlertView *cantRecordAlert =
[[UIAlertView alloc] initWithTitle: @"Warning"
message: @"Audio input hardware not available"
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[cantRecordAlert show];
[cantRecordAlert release];
return;
}
BOOL st = [recorder prepareToRecord];
if(!st){
NSLog(@"Failed");
}
recorder.meteringEnabled = YES;
BOOL status = [recorder record];
if(!status)
NSLog(@"Failed");
}
-(IBAction)stop:(id)sender{
if([recorder isRecording]){
NSLog(@"Recording...");
}else{
NSLog(@"Not recording...");
}
[recorder stop];
}
私は「開始」メソッドを呼び出す
、それが印刷された「失敗」「prepareToRecord」、および「記録」メソッドを呼び出した後。「停止」メソッドを呼び出すと、「記録していません...」というメッセージが表示されます。
このコードでは間違いがあります。
ありがとうございました。
また、エラーは発生しません。 – jfalexvijay
スタートボタンがありますか?また、開始IBActionにログを入力して、それが入力されていることを確認する必要があります。 – DerekH
私にはスタートボタンがあります。スタートボタンをクリックすると、startメソッドが呼び出されます。 .cafに.m4aを使用すると、エラーが発生します。 – jfalexvijay