是否可以在iOS应用程序上运行IMDB Movies预告片?

时间:2015-06-22 06:26:50

标签: ios objective-c iframe uiwebview imdb

我正在处理显示电影预告片的应用程序,但Apple拒绝我的申请,因为我没有权利在应用程序上显示预告片。现在我想在应用程序中添加IMDB电影预告片。

我经常搜索IMDB SDK for iOS但现在失败了我在IMDB网站上找到了运行电影预告片的嵌入式代码。使用此链接:

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

我正在尝试在UIWebView上运行iframe,但它向我显示白屏,如果我使用dailymotion或vimeo iframe,那么它可以正常工作。

这是我的代码:

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 个答案:

答案 0 :(得分:0)

它不起作用,因为您将YouTube iFrame播放器与IMDB预告片播放器混合在一起。尝试使用YouTube预告片链接:

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]];