【问题标题】:Youtube api iframe with ipad ios7 [closed]带有 ipad ios7 的 Youtube api iframe [关闭]
【发布时间】:2014-03-29 03:29:01
【问题描述】:

随着iOS、iPad 和 iPhone 的最新版本,Youtube 播放器(iframe js 版本)不再工作。我知道 Apple 关于自动播放嵌入视频的新限制......问题是,如果我在 iPad 设备上点击 Youtube 视频播放器,流不会开始,但它只是保持缓冲。

你知道热修复它吗?

【问题讨论】:

  • 朋友,请提供更多细节。
  • 我也遇到这个问题3天没有更新IOS(我更新后)。但是这种变化是存在的,事件和 playVideo() 方法根本不起作用。我也在寻找解决方案。

标签: ios ipad iframe youtube youtube-api


【解决方案1】:

对于 iOS 设备,您应该使用 HTML5 而不是 js API。

只需使用以下代码将视频添加到您的应用:

NSString *videoURL = @"http://www.youtube.com/embed/VIDEO_ID";
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)];

编辑:

根据 cmets,您使用的是 HTML5 而不是 Objective-C,只需将 Demo.html 中的所有代码替换为以下代码:

<iframe class="youtube-player" type="text/html" width="640" height="385" src="http://www.youtube.com/embed/qbexOeoH5hg" allowfullscreen frameborder="0">
</iframe>

这应该适用于 iOS :)

注意:

根据 YouTube 的政策,无法嵌入受保护的视频,因此在尝试播放示例中提到的视频时,您会收到一条错误消息:"This video contains content from "Copyright owner"(VEVO in our example) it is restricted from playback on certain sites, watch it on YouTube",其他不受保护的视频可在所有设备上运行。

【讨论】:

  • 嗯,这不是服务器端代码,它是 ObjectiveC,但是由于您使用的是 HTML5,您能否发布如何将 iframe 添加到您的 HTML5 代码中?
  • 在链接上方查看我的代码!非常感谢!
  • 抱歉耽搁了,我正在开会:),我会看看&反馈...
  • 检查更新的答案:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-12-07
  • 1970-01-01
  • 2016-11-11
  • 1970-01-01
  • 2013-10-14
  • 1970-01-01
  • 2012-08-25
相关资源
最近更新 更多