I want play embedded YouTube video in iOS app using YTPlayerView provided at https://developers.google.com/youtube/v3/guides/ios_youtube_helper
When I tried to play
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.
Swift 5.0
@IBOutlet weak var videoPlayer: YTPlayerView!
self.videoPlayer.load(withVideoId: "M7lc1UVf-VE", playerVars: ["origin": "http://www.youtube.com"])
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