2010-05-18 23 views
5

Voglio inizializzare un AVAudioRecorder con un formato di file AAC, ma non lavorare ...inizializzazione di AVAudioRecorder con aac

Cosa c'è di sbagliato con il seguente codice?

soundFilePath = [soundFilePath stringByAppendingPathExtension:@"aac"]; 
NSURL *url = [NSURL fileURLWithPath:soundFilePath isDirectory:FALSE]; 
NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc] init]; 
[recordSetting setValue:[NSNumber numberWithInt: 'aac '] forKey:AVFormatIDKey];          //General Audio Format Settings 
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];         //   " 
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];         //   " 
[recordSetting setValue:[NSNumber numberWithInt: 32] forKey:AVLinearPCMBitDepthKey];        //Linear PCM Format Settings 
[recordSetting setValue:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];        //   " 
[recordSetting setValue:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];         //   " 
[recordSetting setValue:[NSNumber numberWithInt:AVAudioQualityLow] forKey:AVEncoderAudioQualityKey];    //Encoder Settings 
[recordSetting setValue:[NSNumber numberWithInt:96] forKey:AVEncoderBitRateKey];         //   " 
[recordSetting setValue:[NSNumber numberWithInt:16] forKey:AVEncoderBitDepthHintKey];        //   " 
[recordSetting setValue:[NSNumber numberWithInt:AVAudioQualityLow] forKey:AVSampleRateConverterAudioQualityKey]; //Sample Rate Conversion Settings 

_recorder = [[AVAudioRecorder alloc] initWithURL:url settings:recordSetting error:nil]; 

questa allocazione restituisce solo nil ...

Qualsiasi aiuto sarà apprezzato ...!

risposta

-1

[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatMPEG4AAC_HE_V2] forKey:AVFormatIDKey]; Il formato per questa è un'enumerazione. Prova a esaminare le enumerazioni. Non c'è ID di formattazione per 'aac'. Ha aacp e altri.

+0

C'è un "aac" 'formatIDKey': kAudioFormatMPEG4AAC. – memmons

-1

Basta usare le seguenti impostazioni per registrare la voce in un file aac.

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];
+1

Il formato Apple Lossless è _non_ AAC. – memmons

1

iOS 5 consente di registrare in AAC. Prova questo usando "kAudioFormatMPEG4AAC" per AVFormatIDKey.

3

Rimuovere ogni linea su PCM, e la linea di cambiamento con formatIDKey per

[NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey, 

Btw, è più corretto di utilizzare m4a come estensione, piuttosto che aac, perché l'estensione AAC è stata utilizzata per il formato MPEG2 AAC.

Problemi correlati