简体   繁体   English

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

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

When using the AVPlayerViewController , the user is allowed to select whether the subtitles are on a specific language, off , or set to auto .使用AVPlayerViewController时,允许用户选择字幕是使用特定语言、 off还是设置为auto Setting the requiresFullSubtitles property I can force the display of subtitles, but that is not what I want.设置requiresFullSubtitles属性我可以强制显示字幕,但这不是我想要的。

Is there a way to detect what the user has selected for the subtitle setting, whether a language is selected, off , or auto ?有没有办法检测用户为字幕设置选择了什么,是否选择了语言、 offauto

正在播放信息中心

When using the AVPlayerViewController , the user is allowed to select whether the subtitles are on a specific language, off , or set to auto .使用AVPlayerViewController ,允许用户选择字幕是使用特定语言、 off还是设置为auto Setting the requiresFullSubtitles property I can force the display of subtitles, but that is not what I want.设置requiresFullSubtitles属性我可以强制显示字幕,但这不是我想要的。

Is there a way to detect what the user has selected for the subtitle setting, whether a language is selected, off , or auto ?有没有办法检测用户为字幕设置选择了什么,是选择了语言, off还是auto

正在播放信息中心

When using the AVPlayerViewController , the user is allowed to select whether the subtitles are on a specific language, off , or set to auto .使用AVPlayerViewController ,允许用户选择字幕是使用特定语言、 off还是设置为auto Setting the requiresFullSubtitles property I can force the display of subtitles, but that is not what I want.设置requiresFullSubtitles属性我可以强制显示字幕,但这不是我想要的。

Is there a way to detect what the user has selected for the subtitle setting, whether a language is selected, off , or auto ?有没有办法检测用户为字幕设置选择了什么,是选择了语言, off还是auto

正在播放信息中心

When using the AVPlayerViewController , the user is allowed to select whether the subtitles are on a specific language, off , or set to auto .使用AVPlayerViewController ,允许用户选择字幕是使用特定语言、 off还是设置为auto Setting the requiresFullSubtitles property I can force the display of subtitles, but that is not what I want.设置requiresFullSubtitles属性我可以强制显示字幕,但这不是我想要的。

Is there a way to detect what the user has selected for the subtitle setting, whether a language is selected, off , or auto ?有没有办法检测用户为字幕设置选择了什么,是选择了语言, off还是auto

正在播放信息中心

Swift version of @kotvaska @kotvaska 的 Swift 版本

You can add this observer while configuring session/periodic observers您可以在配置会话/定期观察者时添加此观察者

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

For CC you can give a shot to this notification as CC(Closed Captions) is completely different from Subtitles .对于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.

相关问题 使用 AVPlayerViewController 快速显示字幕 - Displaying subtitles using AVPlayerViewController with swift 如何在 Swift 中使用 AVPlayerViewController 检测全屏模式? - How to detect fullscreen mode using AVPlayerViewController in Swift? 如何禁用AVPlayerViewController中的音频和字幕设置 - How to disable the audio and subtitles settings in AVPlayerViewController 如何使用 AVPlayerViewController 检测播放控件显示的切换? - How to detect the toggle on the display of playback controls with AVPlayerViewController? 用户搜索时未调用AVPlayerViewController委托函数 - AVPlayerViewController delegate function not called when user seek 有没有办法在AVPlayerViewController中显示自定义字幕字幕的名称 - Is there a way to show custom subtitles track name in AVPlayerViewController Apple tvOS:AVPlayerViewController上的“隐藏字幕”菜单选项 - Apple tvOS: Hide subtitles menu option on AVPlayerViewController 在swift中,如何在AVPlayerViewController中播放视频时检测触摸 - In swift, how to detect touch while playing video in AVPlayerViewController 如何使用AVPlayerViewController以横向方向旋转屏幕? - How to rotate screen in landscape orientation using AVPlayerViewController? 使用 AVPlayerViewController 时,当用户点击主页按钮时,视频在后台播放,但当返回应用程序时,视频会自行关闭 - While using AVPlayerViewController, video plays in the background when user hits home button, but when returning to app the video closes by itself
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM