【问题标题】:Is it possible to run IMDB Movies trailer on iOS application?是否可以在 iOS 应用程序上运行 IMDB 电影预告片?
【发布时间】:2015-09-07 12:17:18
【问题描述】:

我正在开发显示电影预告片的应用程序,但 Apple 拒绝了我的申请,因为我无权在应用程序中显示预告片。现在我想在应用程序中添加 IMDB 电影预告片。

我搜索了很多以找到适用于 iOS 的 IMDB SDK,但现在我在 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];

【问题讨论】:

    标签: ios objective-c iframe uiwebview imdb


    【解决方案1】:

    它不起作用,因为您将 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]];
    

    【讨论】:

      猜你喜欢
      • 2015-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-28
      • 2014-01-18
      • 1970-01-01
      • 1970-01-01
      • 2019-12-19
      相关资源
      最近更新 更多