Cómo bucle de audio mientras combina audio y video

Estoy siguiendo este código para combinar files de audio y video. Funciona muy bien Suponga que la duración del audio es de 5 segundos y la duración del video es de 20 segundos. Mientras combiné estos files en el video exportado, no hay sonido después de 5 segundos. Eso es obvio porque mi longitud de audio es de 5 segundos. Pero es posible ejecutar el bucle de audio en toda la session de video.

var finalVideoURL = NSURL() var finalVideoName = String() func mergeAudio&VideoFiles(videoUrl:NSURL, audioUrl:NSURL){ let mixComposition : AVMutableComposition = AVMutableComposition() var mutableCompositionVideoTrack : [AVMutableCompositionTrack] = [] var mutableCompositionAudioTrack : [AVMutableCompositionTrack] = [] let totalVideoCompositionInstruction : AVMutableVideoCompositionInstruction = AVMutableVideoCompositionInstruction() //start merge let aVideoAsset : AVAsset = AVAsset(url: videoUrl as URL) let aAudioAsset : AVAsset = AVAsset(url: audioUrl as URL) mutableCompositionVideoTrack.append(mixComposition.addMutableTrack(withMediaType: AVMediaTypeVideo, prefernetworkingTrackID: kCMPersistentTrackID_Invalid)) mutableCompositionAudioTrack.append( mixComposition.addMutableTrack(withMediaType: AVMediaTypeAudio, prefernetworkingTrackID: kCMPersistentTrackID_Invalid)) let aVideoAssetTrack : AVAssetTrack = aVideoAsset.tracks(withMediaType: AVMediaTypeVideo)[0] let aAudioAssetTrack : AVAssetTrack = aAudioAsset.tracks(withMediaType: AVMediaTypeAudio)[0] do{ try mutableCompositionVideoTrack[0].insertTimeRange(CMTimeRangeMake(kCMTimeZero, aVideoAssetTrack.timeRange.duration), of: aVideoAssetTrack, at: kCMTimeZero) try mutableCompositionAudioTrack[0].insertTimeRange(CMTimeRangeMake(kCMTimeZero, aVideoAssetTrack.timeRange.duration), of: aAudioAssetTrack, at: kCMTimeZero) }catch{ } totalVideoCompositionInstruction.timeRange = CMTimeRangeMake(kCMTimeZero,aVideoAssetTrack.timeRange.duration ) let mutableVideoComposition : AVMutableVideoComposition = AVMutableVideoComposition() mutableVideoComposition.frameDuration = CMTimeMake(1, 30) mutableVideoComposition.renderSize = CGSize(width: 1280, height: 720) finalVideoURL = NSURL(fileURLWithPath: NSHomeDirectory() + "/Documents/FinalVideo.mp4") finalVideoName = "FinalVideo.mp4" let assetExport: AVAssetExportSession = AVAssetExportSession(asset: mixComposition, presetName: AVAssetExportPresetHighestQuality)! assetExport.outputFileType = AVFileTypeMPEG4 assetExport.outputURL = finalVideoURL as URL assetExport.shouldOptimizeForNetworkUse = true assetExport.exportAsynchronously { () -> Void in switch assetExport.status { case AVAssetExportSessionStatus.completed: print("Export movie to document directory from trimmed audio and mutable video complete :)") case AVAssetExportSessionStatus.failed: print("failed \(assetExport.error)") case AVAssetExportSessionStatus.cancelled: print("cancelled \(assetExport.error)") default: print("complete") } } }