iOS 8 youtube video embed

依然范特西╮ 提交于 2019-11-30 08:57:53

I had the same problem, I solve using this solution

https://developers.google.com/youtube/v3/guides/ios_youtube_helper

also in the YTPlayerView.m (~line: 610) try this changes:

[playerParams setValue:[NSString stringWithFormat: @"%0.00f", self.frame.size.height] forKey:@"height"];
// [playerParams setValue:@"100%" forKey:@"height"];
[playerParams setValue:[NSString stringWithFormat: @"%0.00f", self.frame.size.width] forKey:@"width"];
// [playerParams setValue:@"100%" forKey:@"width"];

Hope this help

Ethan Parker

I worked on this for a while and figured out a solution that works amazingly for my purposes. What was happening in my case is for some reason the iFrame was using some padding that needed to be discarded.

Also important to note is if you include youtube.com as the Base URL it will load much quicker.

Make a UIWebView in your storyboard and connect the @property to it, then reference below.

    CGFloat height = self.webView.frame.size.height;
    CGFloat width = self.webView.frame.size.width;
    NSString *youTubeVideoCode = @"dQw4w9WgXcQ";
    NSString *embedHTML = @"<iframe width=\"%f\" height=\"%f\" src=\"http://www.youtube.com/embed/%@\" frameborder=\"0\" style=\"margin:-8px;padding:0;\" allowfullscreen></iframe>";
    NSString *html = [NSString stringWithFormat:embedHTML, width, height, youTubeVideoCode];
    self.webView.scrollView.bounces = NO;
    [self.webView loadHTMLString:html baseURL:[NSURL URLWithString:@"http://www.youtube.com"]];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!