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

问题描述

我希望使用

当我尝试使用ID =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"))


推荐答案

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

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 :: 正常情况。

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

10-30 04:44