[英]How to detect user selection of subtitles when using AVPlayerViewController
您可以在配置会话/定期观察者时添加此观察者
NotificationCenter.default.addObserver(
self,
selector: #selector(didMediaToggle(_:)),
name: AVPlayerItem.mediaSelectionDidChangeNotification,
object: nil
)
@objc func didMediaToggle(_ sender: Notification) {
print("LOGGER: mediaSelectionDidChangeNotification:", sender.description)
let subtitles = player.currentItem?.asset.mediaSelectionGroup(forMediaCharacteristic: .legible)
print("LOGGER: mediaSelectionDidChangeNotification: subtitles:", subtitles)
}
/// this will not be called in case of `CC`, aka only `On` and `Off` case
对于CC ,您可以试一下这个通知,因为CC(Closed Captions)与Subtitles完全不同。
NotificationCenter.default.addObserver(
self,
selector: #selector(didCaptionsToggle(_:)),
name: UIAccessibility.closedCaptioningStatusDidChangeNotification,
object: nil
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.