使用AVPlayer的直播静音音轨 [英] Mute audio tracks of live streams using AVPlayer

查看:528
本文介绍了使用AVPlayer的直播静音音轨的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用AVPlayer播放实时流(M3U8文件)。它起着非常使用AVPlayer,但我不能静音。

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

我使用以下code将音频静音。

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

在相同的code我能静音本地视频文件,以及我在同AVPlayer code在玩渐进式视频网址。

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.

(可能是现场直播视频,跟踪AVPlayer例如可用可设置音量为零,但下一个缓冲轨道与体积的新鲜,我说的对或任何其他原因?)

(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?)

任何人有任何关于此问题的想法。任何帮助是非常AP preciable。

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

推荐答案

您的假设是正确的。你不能静音正在播放一个HTTP实时流的球员。我已经提交的这个雷达。

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

在我的应用程序,我们控制流,因此我们制作了没有音频,并与音频相同的流的流,并且2之间切换打开和关闭声音。这是你能做的最好的。

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.

该AVAudioMix解决方案不会对实时流工作。我试过了。看看上说,它仅适用于基于文件的资产底部的注​​意事项:
http://developer.apple.com/library/ios/#qa /qa1716/_index.html

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

它看起来像Mac开发得到他们的AVPlayer一个静音属性,但iOS不具备呢。

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.

这篇关于使用AVPlayer的直播静音音轨的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆