YouTube Embed player in Iframe doesn't work in iOS6

点点圈 提交于 2019-12-04 07:25:26

you can use webview as youtube player

Try Below Code it is working for me

in .h file

@property (strong, nonatomic) UIWebView *webView;

and in your .m file

    NSString *videoURL = @"http://www.youtube.com/embed/M7lc1UVf-VE?autoplay=1&origin=http://example.com";

// if your url is not in embed format or it is dynamic then you have to convert it in embed format.

    videoURL = [videoURL stringByReplacingOccurrencesOfString:@"watch?v=" withString:@"embed/"];

    NSRange range = [videoURLString rangeOfString:@"&"];
    @try {
         videoURLString = [videoURLString substringToIndex:range.location];
    }
    @catch (NSException *exception) {

    }

    // here your link is converted in embed format.

    NSString* embedHTML = [NSString stringWithFormat:@"\
    <html><head>\
    <style type=\"text/css\">\
    iframe {position:absolute; top:50%%; margin-top:-130px;}\
    body {\
        background-color: transparent;\
    color: white;\
    }\
    </style>\
    </head><body style=\"margin:0\">\
    <iframe width=\"100%%\" height=\"240px\" src=\"%@\" frameborder=\"0\" allowfullscreen></iframe>\
    </body></html>",videoURL];

    self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
    [self.view addSubview:self.webView];
    [self.webView loadHTMLString:embedHTML baseURL:nil];

Here you can change webview frame as you want and also can change videoUrl.

There are two concepts, embeddable and syndicated. iOS devices use iframe so they basically embed. Android devices that use player API can check syndicated.

When you do a search->list, you can set videoEmbeddable and videoSyndicated to true.

Or if you are iterating through videos, for each video, you can do a video->list call with video id and check status.embeddable in the response.

Here is a blog post about this topic, even though examples are in v2, information is still relevant.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!