如何使用WkWebView内联播放视频 [英] How to play video inline with WkWebView
问题描述
使用iphone在网络视图中播放视频时,该视频会在本机播放器中以全屏模式打开.
When you use an iphone and play video in a webview, this video is open in the native player in fullscreen.
我们尝试将UIWebView和WKWebView的"allowsInlineMediaPlayback"属性设置为true.但是,Web内容中的视频是通过iphone iOS 10.2全屏启动的.你知道我能做什么吗?
We have tried UIWebView and WKWebView with "allowsInlineMediaPlayback" property to true. But the video in the web content launch in fullscreen with an iphone iOS 10.2. Have you and idea what i can do ?
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)
Env:Xcode 8,Swift 3
Env : Xcode 8, swift 3
推荐答案
您的代码没有问题,但是您需要再执行一步,您使用的视频URL
应该始终带有参数playsinline=1
.
There is no problem for your code,but you need one more step, the video URL
you use should always with a parameter playsinline=1
.
//step1
if let videoURL:URL = URL(string: "https://somevideo.mp4?playsinline=1")
//step2
webConfiguration.allowsInlineMediaPlayback = true
然后您可以做剩下的事情.
then you can do the left things.
这篇关于如何使用WkWebView内联播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!