在 iOS 上禁用全屏自动播放 [英] Disabling auto-play in full screen on iOS
问题描述
我遇到的唯一问题是我无法根据苹果文档禁用全屏播放视频,这是默认启用的,需要如下设置:
The only problem i'm having is that i'm unable to disable playing videos on full screen according to apple documentation this is enabled by default and needs to be set as follows:
webView.configuration.allowsInlineMediaPlayback = true
这是基于我的理解.但是,这不起作用,即使在您按下视频播放后立即进行配置,它也会在本机全屏播放器中打开.我正在使用 WKWebView.
Which is based on my understanding how it's supposed to be. However this doesn't work and even after configuration right after you press play on video it opens up in native full screen player. I'm using WKWebView.
推荐答案
播放视频内联需要两个先决条件:
Playing a video inline requires two prerequisites:
- 设置配置
- 提供格式正确的链接
1.设置配置
WKWebView 的配置需要在初始化时进行设置.稍后修改 allowsInlineMediaPlayback
将不起作用:
let configuration = WKWebViewConfiguration()
configuration.allowsInlineMediaPlayback = true
let webView = WKWebView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height), configuration: configuration)
view.addSubview(webView)
2.提供格式正确的链接
为了让网络视图知道视频应该开始内联播放,需要设置适当的 URL 参数.
2. Providing a correctly formatted link
In order for the web view to know that the video should start playing inline the appropriate URL parameter needs to be set.
为此,您只需附加 ?playsinline=1
.
示例:
webView.load(URLRequest(url: URL(string: "https://www.youtube.com/watch?v=OYbXaqQ3uuo?playsinline=1")!))
这篇关于在 iOS 上禁用全屏自动播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!