Recently I want to set volume of multiple audio track and add into AVMutableComposition using composition.addMutableTrack(withMediaType: .audio, preferredTrackID: CMPersistentTrackID())
This process is in for loop and after I play AVMutableComposition into AVPlayer. but i am not able to set volume of each track we only set volume of AVMutableComposition after adding all track.
So pls advice how can i set volume of multiple audio track and play into AVPlayer.
I am trying this below code but i am not able to set volume of each track.
Here, asset is multiple so, i am add into trackMixArray
var trackMixArray = [AVMutableAudioMixInputParameters]()
let asset = AVAsset(url: audioUrl)
let assetTrack = asset.tracks(withMediaType: AVMediaType.audio)[0]
let trackMix = AVMutableAudioMixInputParameters(track: assetTrack)
trackMix.setVolume(0.0, at: CMTime.zero)
trackMixArray.append(trackMix)
-------
var queue: AVPlayer = AVPlayer()
let audioMix = AVMutableAudioMix()
audioMix.inputParameters = trackMixArray
let playerItem = AVPlayerItem(asset: composition)
playerItem.audioMix = audioMix
self.queue.replaceCurrentItem(with: playerItem)