简体   繁体   中英

Detect when the user has muted AVPlayer

I am playing a live stream using AVPlayer and AVPlayerItem. 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.

Documentation:

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

You can use a combination of KVO and Combine to observe changes to isMuted property:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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