iOS如何合并mp3格式的文件

如果使用的AVAssetExportSession只支持合成m4a文件,其他的各种库也都是从caf、pcm合成的

所以这里使用数据流的形式把MP3文件转成NSData,然后再进行拼合。

//音频文件路径

NSString *mp3Path1 = [[NSBundle mainBundle] pathForResource:@"mouse" ofType:@"mp3"];

NSString *mp3Path2 = [[NSBundle mainBundle] pathForResource:@"large" ofType:@"mp3"];

NSString *mp3Path3 = [[NSBundle mainBundle] pathForResource:@"strong" ofType:@"mp3"];

//音频数据

NSData *sound1Data = [[NSData alloc] initWithContentsOfFile: mp3Path1];

NSData *sound2Data = [[NSData alloc] initWithContentsOfFile: mp3Path2];

NSData *sound3Data = [[NSData alloc] initWithContentsOfFile: mp3Path3];

//合并音频

NSMutableData *sounds = [NSMutableData alloc];

[sounds appendData:sound1Data];

[sounds appendData:sound2Data];

[sounds appendData:sound3Data];

//保存音频

NSLog(@"data length:%d", [sounds length]);

[sounds writeToFile:[self filePathWithName:@"tmp.mp3"] atomically:YES];

你可能感兴趣的:(iOS如何合并mp3格式的文件)