オーディオの録音と IOS での再生に関する問題に直面しています。
録音に使用するものは次のとおりです。
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *err = nil;
[audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];
if(err){
NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
return;
}
[audioSession setActive:YES error:&err];
err = nil;
if(err){
NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
return;
}
recordSettings = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithFloat: 16000.0],AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatLinearPCM], AVFormatIDKey,// kAudioFormatLinearPCM
[NSNumber numberWithInt:8],AVLinearPCMBitDepthKey,
[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
[NSNumber numberWithBool:NO],AVLinearPCMIsBigEndianKey,
[NSNumber numberWithBool:NO],AVLinearPCMIsFloatKey,
[NSNumber numberWithInt: AVAudioQualityLow],AVEncoderAudioQualityKey,
nil];
recorderFilePath = [[NSString stringWithFormat:@"%@/%@", filePath, fileName] retain];
NSLog(@"recorderFilePath: %@",recorderFilePath);
NSURL *audioFileURL = [NSURL fileURLWithPath:recorderFilePath];
recorder = [[ AVAudioRecorder alloc] initWithURL:audioFileURL settings:recordSettings error:&err];
if(!recorder){
NSLog(@"recorder: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
UIAlertView *alert =
[[UIAlertView alloc] initWithTitle: @"Warning"
message: [err localizedDescription]
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
return;
}
//prepare to record
[recorder setDelegate: self];
[recorder prepareToRecord];
recorder.meteringEnabled = YES;
[recorder record];
そして、上記の設定の.wavファイルで、録音は私にとってはうまくいきます。さて、問題は再生です。
以下は、録音された .wav オーディオ ファイルを再生するためのものです。
NSURL * url = [NSURL fileURLWithPath:filePath];
audioPlayer = [[[AVAudioPlayer alloc] initWithContentsOfURL:url
error:&err] autorelease];
if (! audioPlayer) {
NSLog(@"Sound named '%@' had error %@", name, [err localizedDescription]);
} else {
[audioPlayer prepareToPlay]; // Getting the return value NO here.
}
// audioPlayer.volume = 1; // Tried setting different values, but of no help.
[audioPlayer play]; // Getting the return value NO here.
エラーはスローされませんが、何もしません。サウンドが再生されていません。プレーヤーで「.mp3」ファイル(リソースからのテスト ファイル)を再生することは可能ですが、上記の設定で記録されたファイルを再生するには問題があります。
ここで何が欠けているのかわかりません。助けてください!ありがとう