title: Merge an Audio File with Two Video Files iphone sdk
body: <p>I am wondering how I would combine a given audio file with two video files. I am stuck when it comes to combining the audio but the video is fine, here is what I have done so far</p>
  
  <pre><code>- (IBAction)MergeAndSave:(id)sender{
      if(firstAsset !=nil &amp;&amp; secondAsset!=nil){
          [ActivityView startAnimating];
          //Create AVMutableComposition Object.This object will hold our multiple AVMutableCompositionTrack.
          AVMutableComposition* mixComposition = [[AVMutableComposition alloc] init];
  
          //VIDEO TRACK
          AVMutableCompositionTrack *firstTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
          [firstTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, firstAsset.duration) ofTrack:[[firstAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:kCMTimeZero error:nil];
  
          AVMutableCompositionTrack *secondTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
          [secondTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, secondAsset.duration) ofTrack:[[secondAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:firstAsset.duration error:nil];
  
          //AUDIO TRACK
          if(audioAsset==nil){
  
              NSURL* musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                                         pathForResource:@"click"
                                                         ofType:@"caf"]];
  
              AVMutableCompositionTrack *click = [[AVMediaTypeAudio] initWithContentsOfURL:musicFile error:nil];
              [click insertTimeRange:CMTimeRangeMake(kCMTimeZero, CMTimeAdd(firstAsset.duration, secondAsset.duration))
                                  ofTrack:[[audioAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] atTime:kCMTimeZero error:nil];
  
  
                     }
  </code></pre>
  
  <p>as you can see my code for the audio doesn't work at all</p>