在Swift中将2个音频文件混合在一起的最有效方法是什么? (重叠,不附加)

时间:2018-11-04 17:16:13

标签: swift audiokit avmutablecomposition avkit avcomposition

我尝试了许多方法,但无法正常工作。这些文件在一个文件中互相播放,但不能同时播放。

let composition = AVMutableComposition(urlAssetInitializationOptions: [AVURLAssetPreferPreciseDurationAndTimingKey:true])
let compositionAudioTrack = composition.addMutableTrack(withMediaType: AVMediaType.audio, preferredTrackID: kCMPersistentTrackID_Invalid)
let lineOne = AVAsset(url: urls[0])
let lineTwo = AVAsset(url: urls[1])
do {
    try compositionAudioTrack?.insertTimeRange(CMTimeRange(start: CMTime.zero, duration: lineOne.duration), of: lineOne.tracks.first!, at: CMTime.zero)
    try compositionAudioTrack?.insertTimeRange(CMTimeRange(start: CMTime.zero, duration: lineTwo.duration), of: lineTwo.tracks.first!, at: CMTime.zero)       
} catch {
    print("err")
}

0 个答案:

没有答案