0

Attempting to embed youtube videos with ?rel=0 parameter so that when the video finishes, it does not show related videos in the player, like so:

<iframe width="560" height="315" src="//www.youtube.com/embed/TRrL5j3MIvo?rel=0" frameborder="0" allowfullscreen></iframe>

This works great on desktop browsers, but it seems that on iOS, youtube is removing all the parameters from the end of the url. So when a user watches the whole video then presses 'Done' in the mobile youtube player, the related videos are now shown in the browser. My first thought was to try to append ?rel=0 param on the end with javascript after the page loads, but no luck.

user2994560
  • 1,269
  • 4
  • 18
  • 30

1 Answers1

0

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.

information used from > YouTube Embed player in Iframe doesn't work in iOS6

Community
  • 1
  • 1
harrison
  • 79
  • 1
  • 11