ios - 最近没有在 UIWebView 上使用 iframe 播放器播放 youtube 剪辑

标签 ios objective-c youtube-api

我的 iOS 应用程序使用 UIWebView 上的 youtube iframe 播放器以内联模式播放任何剪辑。以下代码是使用的 HTML 代码。

<html>
<head>
     <style type="text/css">body {background-color: transparent;color: white;}</style>
</head>
 <body style="margin:0">
<iframe src="http://www.youtube.com/embed/e2w8z6mI47U?playsinline=1&rel=0&showinfo=0" width="320" height="240" frameborder="0" allowfullscreen></iframe>
</body>
 </html>

然后,它被传递给 loadHTMLString 方法。

直到最近,该代码都运行良好。但是,我最近注意到我使用的每个剪辑都无法正常播放。显示了待机 View 和播放按钮,但尽管我按下了播放按钮,但播放效果不佳。只显示黑屏。

我还没有找到解决问题的方法。 Youtube Iframe 播放器是否有任何变化或我错过的点数?

最佳答案

我最终通过调用 [videoView setMediaPlaybackRequiresUserAction:NO] 解决了这个问题。
我不完全知道为什么这个方法可以救我。猜测是处理在 youtube 上播放的请求发生了变化。我可以在 youtube 开发者网站上找到以下更改。

January 28, 2014

The playsinline parameter controls whether videos play inline or fullscreen in an HTML5 player on iOS. Setting the value to 1 causes inline playback.

The Selecting content to play section has been updated to explain how to find YouTube video IDs and playlist IDs using the YouTube Data API (v3) rather than the older API version.

The controls parameter's definition has been updated to reflect the fact that the parameter value only affects the time that the Flash player actually loads in IFrame embeds. In addition, for IFrame embeds, the parameter value also determines when the controls display in the player. If you set the parameter's value to 2, then the controls display and the Flash player loads after the user initiates the video playback.

我猜想上述更改之一可能需要额外的信息,这些信息从客户端传递到 youtube 服务器才能正常播放。

更新:
今天,我发现它在没有我的解决方案的情况下也能正常工作。看来这个问题最近已经解决了。

关于ios - 最近没有在 UIWebView 上使用 iframe 播放器播放 youtube 剪辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22090328/

相关文章:

youtube-api - 重新加载 youtube api

java - 安卓 : Searching youtube video from my app

ios - 通过 .podspec 文件创建 .framework

ios - 尝试使用两个颜色查找表过滤图像

objective-c - 如何过滤不包含字符串的 NSMutableArray 对象?

objective-c - 如何使用 Objective C 检测击键?

ios - 检测 AVPlayer 何时播放

iphone - 如何从 google+ 应用程序启动和共享(如果已安装)

objective-c - 创建新实例的类方法

javascript - 使用 jQuery 将参数动态传递到 YouTube API