0

How I can create a crossfader between two sound track with AVAudioplayer?

I must use AVAudiomix? But... how I should use?

1 Answers1

0

AVAudioPlayer does not support using an AVAudioMix. You could try to fade out the playing yourself by directly setting the playback volume but getting the timing right between two AVAudioPlayers will be difficult as AVAudioPlayer is known to have very high and unpredictable latency when starting to play.

One way to accomplish this is to use AVPlayer and AVPlayerItem and AVComposition. You can setup the composition to overlay the two audio files by your desired amount and setup the AVAudioMix fade out the first and fade in the second. This method will let you have precise control over when the audio files play relative to one another.

Jon Steinmetz
  • 4,104
  • 1
  • 23
  • 21
  • mmm for example? For first I setup the [AVCompositionTrackSegment](https://developer.apple.com/library/mac/#documentation/AVFoundation/Reference/AVCompositionTrackSegment_Class/Reference/Reference.html#//apple_ref/occ/cl/AVCompositionTrackSegment) with the property of the tracks selected, next I assign the two track to an array of [AVCompositionTrack](https://developer.apple.com/library/mac/#documentation/AVFoundation/Reference/AVCompositionTrack_Class/Reference/Reference.html#//apple_ref/occ/cl/AVCompositionTrack) and finally assign the array to an AvComposition, right? – Alessandro Belli May 13 '13 at 07:28
  • In other words, can you display me an example? – Alessandro Belli May 13 '13 at 14:15