如何静音AVPlayer中播放的视频?
我正在 AVPlayer 中播放视频,现在我需要在播放时单独静音音频。请建议如何在 Objective C 中进行操作。
谢谢, 苏雷什
Im playing a video in AVPlayer, and now I need to mute the audio alone while playing it. Please suggest how to do in objective C.
Thanks,
Suresh
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
从 iOS7 开始,您可以将 AVPlayer
isMulated
属性设置为true
。在 Objective C 中,该属性称为
muted
。参考: https://developer.apple.com/documentation/avfoundation/avplayer/1387544 -istmuted
Since iOS7 you can set the AVPlayer
isMuted
property totrue
.In Objective C the property is called
muted
.Reference: https://developer.apple.com/documentation/avfoundation/avplayer/1387544-ismuted
对于Swift 4以上版本使AVPlayer视频静音
For Swift 4 above to make AVPlayer video mute
这应该可以帮助你渡过难关...
This should see you through...
SWIFT 2.0 和 SWIFT 3.0 (截至 2017 年 7 月 5 日)
对于那些对 Swift 感到好奇的人来说,这只是:
OBJECTIVE-C 的最简单方法:
SWIFT 2.0 and SWIFT 3.0 (As of July 5, 2017)
For those of you curious about Swift it is simply just:
EASIEST way for OBJECTIVE-C:
player.isMulated = true
不适合我。就我而言,我需要视频永久静音。所以我使用下面的代码来实现这一点。
player.isMuted = true
is not working for me.In my case I need the video permanently mute. So I used the below code to achieve this.
当视频处于播放状态时,您需要设置 muted false。
添加监听器:
代码:
You need set muted false when the video is playing status.
add listener:
code:
iOS 音频静音/取消静音
iOS 设备具有静音模式。默认设备开启静音模式时(红点)不播放音频。
当您打开系统的照片应用程序时,您会发现:
AVPlayer
您可以更改
AVPlayer.isMulated
属性默认情况下,它与静默模式绑定。要在静音模式打开时播放音频,请设置音频播放类别(例如,当应用程序启动时)
还要检查
AVLayer.volume
是否不为零以听到音轨iOS mute/unmute audio
iOS devise has Silent mode. When Silent mode is On(red dot) by default device doesn't play audio.
When you open system's Photo app you find that:
As for AVPlayer
You are able to change
AVPlayer.isMuted
propertyBy default it is bounded with Silent mode. To play audio when Silent mode is on set audio playback category(e.g when app is started)
Also check that
AVLayer.volume
is not zero to hear an audio track