WKWebView 视频内联 iOS Xcode [英] WKWebView video inline iOS Xcode

查看:41
本文介绍了WKWebView 视频内联 iOS Xcode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 WKWebView 播放从 youtube INLINE 嵌入的视频.但是,我无法解决该问题,因为我的视频在单击播放时仍会自动全屏显示.我已经花了几个小时,但我仍然找不到解决方案.我会很感激你的帮助,请.这是我的代码:

I tried to play video embedded from youtube INLINE using WKWebView. However, I couldn't be able to fix that problem because my video still automatically go to full screen when I click to play it. I've spent several hours already, but I still couldn't find a solution yet. I'll appreciate your help, pls. Here is my code:

@IBOutlet weak var myPlayer: WKWebView!
override func viewDidLoad() {
    super.viewDidLoad()

    let videoId = "9n1e1N0Sa9k"
    if let mediaURL:URL = URL(string: "https://www.youtube.com/embed/\(videoId)?playsinline=1") {
        let request:URLRequest = URLRequest(url: mediaURL)
        myPlayer.load(request)
    }
}

推荐答案

这里有你想要的解决方案,我以编程方式制作播放器并更改了一些代码.

Here is a solution as you want, i make player programatically and change some code.

var myPlayer: WKWebView!

    override func viewDidLoad() {
        super.viewDidLoad()

        let webConfiguration = WKWebViewConfiguration()
        webConfiguration.allowsInlineMediaPlayback = true
        webConfiguration.mediaTypesRequiringUserActionForPlayback = []

        myPlayer = WKWebView(frame: CGRect(x: 0, y: 0, width: 375, height: 300), configuration: webConfiguration)
        self.view.addSubview(myPlayer)

        if let videoURL:URL = URL(string: "https://www.youtube.com/embed/9n1e1N0Sa9k?playsinline=1") {
             let request:URLRequest = URLRequest(url: videoURL)
             myPlayer.load(request)
        }
    }

这篇关于WKWebView 视频内联 iOS Xcode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆