Reputation: 61
I need to record audio file that can be played with silverlight. Audio files recorded with AVAudioRecorder have CAF container. This format is not supported by silverlight. Is there any way to edit the audio so that it has mp4 container so that it would be supported by silverlight.
Upvotes: 2
Views: 3064
Reputation: 355
The container format is determined by the extension of the URL you specify when creating the AVAudioRecorder.
NSString *tempDir = NSTemporaryDirectory ();
NSString *soundFilePath = [tempDir stringByAppendingString: @"sound.mp4"];
You can see here that the extension specified is mp4. Upon creating the recorder, we specify the codec format (here it is plain AAC):
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryRecord error: nil];
NSDictionary *recordSettings = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithFloat: 32000], AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
nil];
AVAudioRecorder *newRecorder = [[AVAudioRecorder alloc] initWithURL: soundFilePath settings: recordSettings error: nil];
[recordSettings release];
self.soundRecorder = newRecorder;
[newRecorder release];
soundRecorder.delegate = self;
[soundRecorder prepareToRecord];
[soundRecorder recordForDuration:60];
The resulting file will be a AAC compressed stream within an "ISO Media, MPEG v4 system, version 2" container (as of iOS 5.0).
If you specify and extension with "caf" then the container will be Core Audio Format an the codec will still be AAC.
Upvotes: 7
Reputation: 61
Well I guess there is a way after all. All that is needed to save the file with .mp4 extension. The AVAudioRecorder creates the container according to the extension stated in the file path to save the audio file. I did not assume it is just that easy but it works perfectly :)
Upvotes: 2
Reputation: 40502
Sadly, there is no built-in way to either record as an mp4 or convert a CAF to an mp4. File a bug report with Apple as I have done.
Upvotes: 0