当您使用 iPhone 并在 WebView 中播放视频时,此视频会在 native 播放器中全屏打开。
我们已经尝试将“allowsInlineMediaPlayback”属性设置为 true 的 UIWebView 和 WKWebView。但是网络内容中的视频在 iPhone iOS 10.2 上以全屏模式启动。你知道我能做什么吗?
let webConfiguration = WKWebViewConfiguration()
// Fix Fullscreen mode for video and autoplay
webConfiguration.preferences.javaScriptEnabled = true
webConfiguration.mediaPlaybackRequiresUserAction = false
webConfiguration.allowsInlineMediaPlayback = true
webView = WKWebView(frame: CGRect(x: 0, y: 0, width:self.backgroundView.frame.width, height:self.backgroundView.frame.height), configuration: webConfiguration)
环境:Xcode 8,swift 3
最佳答案
您的代码没有问题,但您还需要一个步骤,您使用的视频URL
应始终带有参数playsinline=1
。
//step1
if let videoURL:URL = URL(string: "https://somevideo.mp4?playsinline=1")
//step2
webConfiguration.allowsInlineMediaPlayback = true
然后你可以做左边的事情。
关于iphone - 如何使用 WkWebView 内联播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43885705/