Is it possible to run IMDB Movies trailer on iOS application?

498 views Asked by At

I'm working on application which shows movie trailer but Apple reject my application because i've no right to show trailer on application. Now i want to add IMDB movie trailers in application.

I search a lot to find IMDB SDK for iOS but failed now i find embedded Code on IMDB website which run movie trailer. Using this link:

How to embed YouTube video on iOs and play it directly on UIWebview without full screen

i'm trying to run iframe on UIWebView but it shows me white screen, if i used dailymotion or vimeo iframe then it works fine.

Here is my code:

self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 20,320, 568)];
[self.webView setAllowsInlineMediaPlayback:YES];
[self.webView setMediaPlaybackRequiresUserAction:NO];

[self.view addSubview:self.webView];

NSString* embedHTML = [NSString stringWithFormat:@"<html><body style='margin:0px;padding:0px;'><script type='text/javascript' src='http://www.youtube.com/iframe_api'></script><script type='text/javascript'>function onYouTubeIframeAPIReady(){ytplayer=new YT.Player('playerId',{events:{onReady:onPlayerReady}})}function onPlayerReady(a){a.target.playVideo();}</script><iframe src='http://www.imdb.com/video/imdb/vi2198188057//embed?autoplay=false&width=480' width='480' height='270' allowfullscreen='true' mozallowfullscreen='true' webkitallowfullscreen='true' frameborder='no' scrolling='no'></iframe></body></html>"];
[self.webView loadHTMLString:embedHTML baseURL:nil];
1

There are 1 answers

0
JAL On

It doesn't work because you're mixing the YouTube iFrame player with the IMDB trailer player. Try using the YouTube trailer link:

NSString *videoID = @"HCdUubr70i8"; // https://www.youtube.com/watch?v=HCdUubr70i8

// Adjust the width and height to your liking, I just pass in the view's frame width and height
NSString *str = [NSString stringWithFormat:@"<html><body style='margin:0px;padding:0px;'><script type='text/javascript' src='http://www.youtube.com/iframe_api'></script><script type='text/javascript'>function onYouTubeIframeAPIReady(){ytplayer=new YT.Player('playerId',{events:{onReady:onPlayerReady}})}function onPlayerReady(a){a.target.playVideo();}</script><iframe id='playerId' type='text/html' width='%@' height='%@' src='http://www.youtube.com/embed/%@?enablejsapi=1&rel=0&playsinline=1&autoplay=1' frameborder='0'></body></html>", self.view.frame.size.width, self.view.frame.size.height, videoID];

[self.webView loadHTMLString:embedHTML baseURL: [[NSBundle mainBundle] bundleURL]];