如何追加两个音频文件? [英] How to append two audio files?

查看:160
本文介绍了如何追加两个音频文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要追加在iPhone两个音频文件。请帮我做到这一点。

I want to append two audio files in iPhone. Please help me to do this.

推荐答案

我得到了解决;以下是示例code做到这一点。

I got the solution; Following is the sample code to do it.

AVMutableComposition* composition = [AVMutableComposition composition];
AVURLAsset* audioAsset1 = [[AVURLAsset alloc]initWithURL:[NSURL fileURLWithPath:filePath1] options:nil];
AVURLAsset* audioAsset2 = [[AVURLAsset alloc]initWithURL:[NSURL fileURLWithPath:filePath2] options:nil];

AVMutableCompositionTrack *audioTrack1 = [composition addMutableTrackWithMediaType:AVMediaTypeAudio 
                                                                      preferredTrackID:kCMPersistentTrackID_Invalid];

[audioTrack1 insertTimeRange:CMTimeRangeMake(kCMTimeZero, audioAsset1.duration)
                         ofTrack:[[audioAsset1 tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0]
                          atTime:kCMTimeZero
                           error:&error];
[audioTrack1 insertTimeRange:CMTimeRangeMake(kCMTimeZero, audioAsset2.duration) 
                         ofTrack:[[audioAsset2 tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] 
                          atTime:audioAsset1.duration
                           error:&error];

最后,我们用它导出为一个单一的文件 AVAssetExportSession

注意:这将只对文件的.m4a

这篇关于如何追加两个音频文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆