[英]Detect when the user has muted AVPlayer
I am playing a live stream using AVPlayer and AVPlayerItem.我正在使用 AVPlayer 和 AVPlayerItem 播放现场直播 stream。 Is there a way to know if the user has muted/unmuted the video while playing it有没有办法知道用户在播放视频时是否静音/取消静音
You can check the isMuted
value of the AVPlayer.您可以检查 AVPlayer 的isMuted
值。
Documentation:文档:
https://developer.apple.com/documentation/avfoundation/avplayer/1387544-ismuted https://developer.apple.com/documentation/avfoundation/avplayer/1387544-ismuted
You can use a combination of KVO
and Combine
to observe changes to isMuted
property:您可以结合使用KVO
和Combine
来观察isMuted
属性的变化:
let player: AVPlayer
private var cancellables = Set<AnyCancellable>()
//...
player
.publisher(for: \.isMuted)
.sink { isMuted in
// here you can handle the fact the the user has muted or unmuted the player
}
.store(in: &cancellables)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.