Using YTPlayerView to play embedded YouTube video in iOS failed with restriction error

烈酒焚心 提交于 2019-11-29 09:58:27

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"
                 ]

Then call loadWithVideoId:: as you normally would.

Mayuri R Talaviya
NSDictionary *playerVars = @{
                             @"origin" : @"http://www.youtube.com",
                             };
[self.playerView loadWithVideoId:@"videoId" playerVars:playerVars];`

This Objective-C version works for me.

YTPlayerView inturn uses iframes to play youtube video. You cannot use iframe in playing copyrighted youtube videos you can use a uiwebView to play this as an alternative

Swift 5.0

@IBOutlet weak var videoPlayer: YTPlayerView!

 self.videoPlayer.load(withVideoId: "M7lc1UVf-VE", playerVars: ["origin": "http://www.youtube.com"])
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!