繁体   English   中英

使用 AVPlayerViewController 时如何检测用户对字幕的选择

[英]How to detect user selection of subtitles when using AVPlayerViewController

使用AVPlayerViewController时,允许用户选择字幕是使用特定语言、 off还是设置为auto 设置requiresFullSubtitles属性我可以强制显示字幕,但这不是我想要的。

有没有办法检测用户为字幕设置选择了什么,是否选择了语言、 offauto

正在播放信息中心

使用AVPlayerViewController ,允许用户选择字幕是使用特定语言、 off还是设置为auto 设置requiresFullSubtitles属性我可以强制显示字幕,但这不是我想要的。

有没有办法检测用户为字幕设置选择了什么,是选择了语言, off还是auto

正在播放信息中心

使用AVPlayerViewController ,允许用户选择字幕是使用特定语言、 off还是设置为auto 设置requiresFullSubtitles属性我可以强制显示字幕,但这不是我想要的。

有没有办法检测用户为字幕设置选择了什么,是选择了语言, off还是auto

正在播放信息中心

使用AVPlayerViewController ,允许用户选择字幕是使用特定语言、 off还是设置为auto 设置requiresFullSubtitles属性我可以强制显示字幕,但这不是我想要的。

有没有办法检测用户为字幕设置选择了什么,是选择了语言, off还是auto

正在播放信息中心

@kotvaska 的 Swift 版本

您可以在配置会话/定期观察者时添加此观察者

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.

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