I tried to solve this problem within 48 hours and did not come up with anything. I have 2 AVPlayer objects that play different streams live on http. Obviously, I do not want them both to play audio at the same time, so I need to disable one of the videos.
Apple offers this to turn off the audio track played in AVPlayer ...
NSMutableArray *allAudioParams = [NSMutableArray array];
for (AVPlayerItemTrack *track in [_playerItem tracks]) {
if ([track.assetTrack.mediaType isEqualToString:AVMediaTypeAudio]) {
AVMutableAudioMixInputParameters *audioInputParams = [AVMutableAudioMixInputParameters audioMixInputParameters];
[audioInputParams setVolume:0.0 atTime:CMTimeMakeWithSeconds(0,1)];
[audioInputParams setTrackID:[track.assetTrack trackID]];
[allAudioParams addObject:audioInputParams];
[track setEnabled:NO];
}
}
AVMutableAudioMix *audioZeroMix = [AVMutableAudioMix audioMix];
[audioZeroMix setInputParameters:allAudioParams];
[_playerItem setAudioMix:audioZeroMix];
When this did not work (after many iterations), I found the enabled AVPlayerItemTrack property and tried to set it to NO. And nothing. It doesn't even register as anything, because when I try to use NSLog (@ "% x", track.enabled), it still displays as 1.
, , , . - , .
* . Apple , AVFoundation, HLS. , , ( , Apple, ),
.