2011-05-12 90 views
2

我需要錄製可以用silverlight播放的音頻文件。使用AVAudioRecorder錄製的音頻文件具有CAF容器。這種格式不受silverlight支持。有沒有辦法編輯音頻,以便它有mp4容器,以便它可以被silverlight支持。將CAF音頻容器更改爲mp4?

回答

2

嗯,我想有一種辦法畢竟。只需使用.mp4擴展名保存文件即可。 AVAudioRecorder根據文件路徑中指定的擴展名創建容器以保存音頻文件。我並不認爲它就是這麼簡單,但它的功能完美:)

0

不幸的是,沒有內置的方式來記錄爲mp4或將CAF轉換爲mp4。像我一樣,用Apple提交錯誤報告。

7

容器格式取決於您在創建AVAudioRecorder時指定的URL的擴展名。

NSString *tempDir = NSTemporaryDirectory(); 
NSString *soundFilePath = [tempDir stringByAppendingString: @"sound.mp4"];  

你可以在這裏看到指定的擴展名是mp4。在創建記錄,我們指定的編解碼格式(這裏是平原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]; 

生成的文件會被一個AAC的內壓縮流「ISO媒體,MPEG V4系統,第2版」容器(如的iOS 5.0)。

如果用「caf」指定和擴展,那麼容器將是Core Audio Format,編解碼器仍然是AAC。

相關問題