title: How to change the volume of a track in AVMutableComposition
body: <p>I have been trying different approaches to this problem, but they take too long to process (alter the MP3 file for different volumes).</p>
  
  <p>I have an AVMutableComposition that gets filled with several AVMutableCompositionTrack for audio and video. The mixing works fine but the adjustment in the volume for the audio track is not working and fails when exporting.</p>
  
  <p>Here is the code I use:</p>
  
  <pre><code>AVMutableComposition* mixComposition = [AVMutableComposition composition];
  AVURLAsset *soundTrackAsset = [[AVURLAsset alloc]initWithURL:trackTempProcessedURL options:nil];
  
  //ADDING AUDIO
  AVMutableCompositionTrack *compositionAudioSoundTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:trackIDSoundTrack];
  [compositionAudioSoundTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, audioAsset.duration) 
                                      ofTrack:[[soundTrackAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] 
                                       atTime:CMTimeAdd(cmTimeDifference,startTime) error:nil];
  
  NSArray *tracksToDuck = [mixComposition tracksWithMediaType:AVMediaTypeAudio];
  NSMutableArray *trackMixArray = [NSMutableArray array];
  for (NSInteger i = 0; i &lt; [tracksToDuck count]; i++) {
      AVMutableAudioMixInputParameters *trackMix = [AVMutableAudioMixInputParameters audioMixInputParametersWithTrack:[tracksToDuck objectAtIndex:i]];
      [trackMix setVolume:volume atTime:kCMTimeZero];   
      [trackMixArray addObject:trackMix];
   }
   audioMix = [AVMutableAudioMix audioMix];
   audioMix.inputParameters = trackMixArray;
  
  //ADDING VIDEO
  AVURLAsset* videoAsset = [[AVURLAsset alloc]initWithURL:frontAssetURL options:nil];
  [compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration) 
                                 ofTrack:[[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]
                                  atTime:startTime error:nil];
  
  //EXPORTING
  _assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName: AVAssetExportPresetPassthrough];
  
  _assetExport.outputFileType = AVFileTypeQuickTimeMovie; 
  _assetExport.outputURL = exportUrl;
  _assetExport.shouldOptimizeForNetworkUse = YES;
  _assetExport.audioMix = audioMix;  
  
  [_assetExport exportAsynchronouslyWithCompletionHandler:
   ^(void ) { 
   ...
  </code></pre>
  
  <p>Everything mixes fine without the audio mixer but when I try to alter the volume the export gives me an error:</p>
  
  <pre><code>AVFoundationErrorDomain Error: 11822
  </code></pre>