Disable HTTP Stream in AVPlayer

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];
        // Added to what Apple Suggested
        [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, ), .

+5
2

iOS 7: AVPlayer 2 'volume' 'muted'. !


iOS 7:

. . , [player replaceCurrentItemWithPlayerItem:muteStream].

. , AVPlayer MacOS 10.7, iOS.

AVAudioMix URL

, , , , , .

+6

URL- ! , .

, , ComPuff URL-, .

, :

    float volume = 0.0f;

AVPlayerItem *currentItem = self.player.currentItem;
NSArray *audioTracks = self.player.currentItem.tracks;

DLog(@"%@",currentItem.tracks);

NSMutableArray *allAudioParams = [NSMutableArray array];

for (AVPlayerItemTrack *track in audioTracks)
{
    if ([track.assetTrack.mediaType isEqual:AVMediaTypeAudio])
    {
        AVMutableAudioMixInputParameters *audioInputParams = [AVMutableAudioMixInputParameters audioMixInputParameters];
        [audioInputParams setVolume:volume atTime:kCMTimeZero];
        [audioInputParams setTrackID:[track.assetTrack trackID]];
        [allAudioParams addObject:audioInputParams];
    }
}

if ([allAudioParams count] > 0) {
    AVMutableAudioMix *audioMix = [AVMutableAudioMix audioMix];
    [audioMix setInputParameters:allAudioParams];
    [currentItem setAudioMix:audioMix];
}

, URL- ( ), (2 ). , URL- ! - ?

+1

All Articles