当您使用iPhone并在Web View 中播放视频时,该视频会在本机播放器中以全屏模式打开。

我们已经尝试将UIWebView和WKWebView的“allowsInlineMediaPlayback”属性设置为true。但是,网络内容中的视频是通过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/

10-11 20:10