iOS 将.caf文件转换为.aac文件

How to convert .caf audio files into .aac?

step 1) I have downloaded sample TPAACAudioConverter project from https://github.com/michaeltyson/TPAACAudioConverter
从github下载这个项目。

step 2)AACConverterViewController.m

i have set source file and destination file format
进入AACConverterViewController.m,将里面的m4a改为aac

- (IBAction)convert:(id)sender {
.........

NSArray *documentsFolders = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
audioConverter = [[[TPAACAudioConverter alloc] initWithDelegate:self 
                                                         source:[[NSBundle mainBundle] pathForResource:@"audio" ofType:@"aiff"]
                                                    destination:[[documentsFolders objectAtIndex:0] stringByAppendingPathComponent:@"audio.aac"]] autorelease]; //将原来的m4a改为aac
((UIButton*)sender).enabled = NO;
[self.spinner startAnimating];
self.progressView.progress = 0.0;
self.progressView.hidden = NO;

[audioConverter start];
}

play converted audio

- (IBAction)playConverted:(id)sender {
if ( audioPlayer ) {
    [audioPlayer stop];
    [audioPlayer release];
    audioPlayer = nil;
    [(UIButton*)sender setTitle:@"Play converted" forState:UIControlStateNormal];
} else {
    NSArray *documentsFolders = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path = [[documentsFolders objectAtIndex:0] stringByAppendingPathComponent:@"audio.aac"]; //将m4a改为aac
    audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
    [audioPlayer play];

    [(UIButton*)sender setTitle:@"Stop" forState:UIControlStateNormal];
}
}

step 3)TPAACAudioConverter.m
simply i have changed audio file type find and replace kAudioFileM4AType into kAudioFileAAC_ADTSType

进入TPAACAudioConverter.m文件,搜索kAudioFileM4AType,将kAudioFileM4AType改为kAudioFileAAC_ADTSType

答案来自于Stack Overflow

其实关键的部分是第三步,转码用的文件只是TPAACAudioConverter.h和TPAACAudioConverter.m

猜你喜欢

转载自blog.csdn.net/youshaoduo/article/details/84789217