Disable live audio tracks using AVPlayer

I am using AVPlayer for live playback (m3U8 file). It works great with AVPlayer, but I can't turn it off.

I use the following code to mute.

NSMutableArray *allAudioParams = [NSMutableArray array]; for (AVPlayerItemTrack *track in _player.currentItem.tracks) { if ([track.assetTrack.mediaType isEqual:AVMediaTypeAudio]) { AVMutableAudioMixInputParameters *audioInputParams = [AVMutableAudioMixInputParameters audioMixInputParameters]; [audioInputParams setVolume:0.0 atTime:kCMTimeZero]; [audioInputParams setTrackID:[track.assetTrack trackID]]; [allAudioParams addObject:audioInputParams]; } } AVMutableAudioMix *audioZeroMix = [AVMutableAudioMix audioMix]; [audioZeroMix setInputParameters:allAudioParams]; [[_player currentItem] setAudioMix:audioZeroMix]; 

Using the same code, I can disable local video files as well as progressive videos that I play in the same AVPlayer code.

(maybe for live video, the tracks available in the AVPlayer instance can be set as a ZERO volume, but the following buffering tracks are fresh with the volume, am I right or for any other reasons?)

Anyone have an idea on this issue. Any help on this is very noticeable.

+4
source share
2 answers

Your guess is correct. You cannot disable a player that plays HTTP Live streams. I registered RADAR on this.

In my application, we control streams, so we created a stream without sound and an identical stream with sound, and switch between 2 to turn the sound on and off. This is the best you can do.

AVAudioMix does not work in real time. I have tried. Look at the note below, which says that it only works with file assets: http://developer.apple.com/library/ios/#qa/qa1716/_index.html

It looks like Mac Developers get the mute property on their AVPlayer, but iOS doesn't have one yet.

Now you have to get around the problem in your threads if you can.

+3
source

As a workaround, you can use the MPVolumeView class to adjust the volume of any video. This will allow the user to disconnect the video if he wants. But you are unlikely to be able to customize this kind of slider without using the undocumented API.

 MPVolumeView *volumeView = [[[MPVolumeView alloc] initWithFrame: CGRectMake(10, 37, 260, 20)] autorelease]; UIAlertView *volumeAlert = [[UIAlertView alloc] initWithTitle:@"Volume" message:@"" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [volumeView sizeToFit]; [volumeAlert addSubview:volumeView]; [volumeAlert show]; [volumeAlert release]; 
+1
source

All Articles