我尝试在我的应用中播放流媒体视频,但它在 WKWebView/UIWebView 中不起作用。
let url = URL(string: "https://www.youtube.com/embed/PP2G3dm_fsc")
let webView = WKWebView()
webView.frame = CGRect(x: 0, y: 0, width: self.frame.width, height: webViewHeight)
webView.load(URLRequest(url: url!))
webView.isUserInteractionEnabled = true
self.addSubview(webView)
此视频 (PP2G3dm_fsc) 受到限制,但我在任何视频(甚至是我自己的视频)中都收到相同的错误消息。同时这个网址在我的浏览器中就像一个魅力。
我必须使用 YTPlayerView 才能使其工作吗?
更新:我与 YTPlayerView 得到相同的结果
最佳答案
您可以使用youtube-ios-player-helper .
It is an open source library that helps you embed a YouTube iframe player into an iOS application. The library creates a
UIWebView
and a bridge between your application’s Objective-C code and the YouTube player’s JavaScript code, thereby allowing the iOS application to control the YouTube player.
这将使您使用该库更容易实现。您还可以查看他们的GitHub page用于示例实现。
希望这有帮助。
关于swift - UIWebView/WKWebView 和 youtube 流媒体视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46021958/