[英]Detect when the user has muted AVPlayer
我正在使用 AVPlayer 和 AVPlayerItem 播放现场直播 stream。 有没有办法知道用户在播放视频时是否静音/取消静音
您可以检查 AVPlayer 的isMuted
值。
文档:
https://developer.apple.com/documentation/avfoundation/avplayer/1387544-ismuted
您可以结合使用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.