swift - UIWebView/WKWebView 和 youtube 流媒体视频

标签 swift uiwebview youtube-api wkwebview swift4

我尝试在我的应用中播放流媒体视频,但它在 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) 受到限制,但我在任何视频(甚至是我自己的视频)中都收到相同的错误消息。同时这个网址在我的浏览器中就像一个魅力。

enter image description here

我必须使用 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/

相关文章:

swift - 无法停止 iOS scheduleLocalNotification

ios - 如何通过swift打开表情符号键盘

javascript - 视频结束时的youtube api调用功能

youtube - onYouTubePlayerReady没有被调用

iphone - 在 UIWebView 中获取当前 url

php - 如何上传到同一帐户的特定 YouTube channel ? (YouTube 数据 API)

xcode - 我应该将 UIIMageViews 直接放在 Controller 的 View 中吗?

ios - Alamofire 网络获取的完成处理程序

react-native - 当应用程序进入前台时,React Native 停止 WebView 重新加载

ios - 在 (BOOL)webView : How to open a URL clicked in UIWebView that opens a Modal UIWebView 内