4
votes

I am using AVPlayer to play live stream (m3U8 file). It plays perfectly using AVPlayer but I am not able to mute it.

I am using following code to mute the audio.

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];

With the same code I able to mute the local video files as well as progressive video urls which I am playing in same AVPlayer code.

(may be for live stream video , tracks available in AVPlayer instance can be set volume ZERO but next buffering tracks are fresh with volume, am i right or any other reasons?)

Anybody have any idea on this issue. Any help on this is highly appreciable.

2
Anbody having any pointers.. whether its possible or not possible? I went through all the sources, as per my information i got , its not possible in iOS. It is correct?macpandit
I have been slamming my head into my desk for a full day and a half now and haven't come up with a solution. I've checked every relevant object reference documention I can think of. I'm tried the solution mentioned above (as recommended by Apple) as well as trying to set the AVPlayerItemTrack enabled to NO. Nothing seems to work. If anyone else has any suggestions here, I'd love to know.Steve E

2 Answers

3
votes

Your assumption is correct. You cannot mute a player that is playing an HTTP Live Stream. I have filed a RADAR on this.

In my app we control the streams, so we produced a stream with no audio, and an identical stream with audio, and switch between the 2 to turn on and off the sound. It's the best you can do.

The AVAudioMix solution doesn't work on live streams. I tried. Look at the note on the bottom that says it only works on file based assets: http://developer.apple.com/library/ios/#qa/qa1716/_index.html

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

For now, you will have to work around the problem in your streams, if you can.

1
votes

As a workaround you may use the MPVolumeView class to adjust the volume of any video. This will allow the user to mute the video if they desire. But unlikely you can't customize this slider's appearance 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];