[英]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
?有没有办法检测用户为字幕设置选择了什么,是否选择了语言、 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
?
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
?
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.