使用 YTPlayerView 在 iOS 中播放嵌入的 YouTube 视频失败,出现限制错误

Using YTPlayerView to play embedded YouTube video in iOS failed with restriction error(使用 YTPlayerView 在 iOS 中播放嵌入的 YouTube 视频失败,出现限制错误)
本文介绍了使用 YTPlayerView 在 iOS 中播放嵌入的 YouTube 视频失败,出现限制错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 https://developers 提供的 YTPlayerView 在 iOS 应用中播放嵌入的 YouTube 视频.google.com/youtube/v3/guides/ios_youtube_helper

当我尝试使用 ID = "Ri7-vnrJD3k" (https://www.youtube.com/embed/Ri7-vnrJD3k),我收到错误消息此视频包含来自 VEVO 的内容.它被限制在某些网站上播放.在 YouTube 上观看".请注意,播放其他一些视频时不会出现此类问题.

When I tried to play this video with ID = "Ri7-vnrJD3k" (https://www.youtube.com/embed/Ri7-vnrJD3k), I got the error message "This video contains content from VEVO. It is restricted from playback on certain sites. Watch on YouTube". Note that there is no such issue when playing some other videos.

有没有办法解决上述问题?

Is there any way to address the above issue?

我可以使用 iframe 通过以下示例 swift 代码成功播放视频内联.但我不知道如何跟踪用户何时开始播放视频以及视频何时完成,因为我想根据这些信息执行其他自定义操作.如果您知道任何解决方案,请告诉我吗?

I could use iframe to play the video inline successfully with below sample swift code. But I don't know how to track when user starts to play the video and when the video completes since I want to do other custom action based on those information. If you know any solution, could you kindly let me know?

let frame = CGRectMake(0,0, self.view.frame.size.width, 240)
playerView = UIWebView(frame: frame)
playerView.allowsInlineMediaPlayback = true

var embedHTML = NSString(format: "<html><head><style type="text/css"> body { background-color: transparent; color: white; margin:0; width:100%%; height:100%% } </style> </head><body style="margin:0"> <iframe width=100%% height=100%% src="%@?feature=player_detailpage&playsinline=1" frameborder="0" ></iframe> </body></html>", self.url.text)

self.view.addSubview(playerView)
playerView.loadHTMLString(embedHTML as String, baseURL: NSURL(string: "http://www.youtube.com"))

推荐答案

通过在我的 playerVars 中设置 origin 属性,我能够播放嵌入的视频.

By setting the origin property in my playerVars I was able to play the embedded video.

let playerVars = [
                     "playsinline" : 1,
                     "showinfo" : 0,
                     "rel" : 0,
                     "modestbranding" : 1,
                     "controls" : 1,
                     "origin" : "https://www.example.com"
                 ]

然后像往常一样调用 loadWithVideoId::.

Then call loadWithVideoId:: as you normally would.

这篇关于使用 YTPlayerView 在 iOS 中播放嵌入的 YouTube 视频失败,出现限制错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
Dropbox Files.download does not start when number of files in folder is gt; 1000(当文件夹中的文件数为1000时,Dropbox Files.Download不会启动)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)