オーディオ ファイルを m4a 形式で録音するためのコードを実装しました。ipod では正常に動作しますが、iphone 4s では再生できません。
私のコードは次のとおりです。
-(IBAction)recordAudio:(id)sender
{
NSDictionary * recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue:[NSNumber numberWithInt:kAudioFormatAppleLossless] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
[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];
NSString *task = [[NSUserDefaults standardUserDefaults]valueForKey:@"accidenttask"];
recordPath= [[NSString stringWithFormat:@"%@/%d.m4a",DOCUMENTS_FOLDER,a_id]retain];
url=[NSURL fileURLWithPath:recordPath];
NSError *err = nil;
if([recorder isRecording])
{
[recorder stop];
recorder = nil;
}
recorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSetting error:&err];
if(err)
NSLog(@"ERROR : %@", err);
BOOL st = [recorder prepareToRecord];
if(!st){
NSLog(@"Failed");
}
recorder.meteringEnabled = YES;
BOOL status = [recorder record];
if(!status)
NSLog(@"Failed");
}
-(IBAction)stop:(id)sender
{
[stopButton setHidden:YES];
[playButton setHidden:NO];
[recordButton setHidden:NO];
[recorder stop];
}
-(IBAction)playAudio:(id)sender
{
[recorder stop];
if (!recorder.recording)
{
NSError *error;
recordPath= [[NSString stringWithFormat:@"%@/%d.m4a",DOCUMENTS_FOLDER,a_id]retain];
NSString *filename=[[filearry objectAtIndex:0]valueForKey:@"audiofile_path"];
url=[ NSURL fileURLWithPath:filename];
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:filename] error:nil];
[audioPlayer setVolume:1.0];
[audioPlayer prepareToPlay];
[audioPlayer play];
}
}
何が問題になる可能性がありますか?