繁体   English   中英

检测用户何时将 AVPlayer 静音

[英]Detect when the user has muted AVPlayer

我正在使用 AVPlayer 和 AVPlayerItem 播放现场直播 stream。 有没有办法知道用户在播放视频时是否静音/取消静音

您可以检查 AVPlayer 的isMuted值。

文档:

https://developer.apple.com/documentation/avfoundation/avplayer/1387544-ismuted

您可以结合使用KVOCombine来观察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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM