I have an AVURLAsset with multiple AVAssetTracks of type audio. I would like to be able to allow user to switch between these different audio track by touching a button. It is working to turn volume of 1st track on and off but other tracks are not heard when volume set to 1.0.
Here is code for adjusting the volume of the tracks (sender is a UIButton with tag set to index of asset in audioTracks).
AVURLAsset *asset = (AVURLAsset*)[[player currentItem] asset];
NSArray *audioTracks = [asset tracksWithMediaType:AVMediaTypeAudio];
NSMutableArray *allAudioParams = [NSMutableArray array];
int i = 0;
NSLog(@"%@", audioTracks);
for (AVAssetTrack *track in audioTracks) {
AVMutableAudioMixInputParameters *audioInputParams = [AVMutableAudioMixInputParameters audioMixInputParameters];
float volume = i == sender.tag ? 1.0 : 0.0;
[audioInputParams setVolume:volume atTime:kCMTimeZero];
[audioInputParams setTrackID:[track trackID]];
[allAudioParams addObject:audioInputParams];
i++;
}
AVMutableAudioMix *audioZeroMix = [AVMutableAudioMix audioMix];
[audioZeroMix setInputParameters:allAudioParams];
[[player currentItem] setAudioMix:audioZeroMix];
Do I need to do something to bring the desired track to be the active one?