使用最新版本的iOS
,iPad和iPhone,Youtube播放器(iframe js版本)不再有效。我知道Apple关于自动播放嵌入视频的新限制......问题是,如果我点击iPad设备上的Youtube视频播放器,流不会启动,但它只是保持缓冲。
你知道热修复吗?
答案 0 :(得分:2)
对于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)];
修改强>
根据评论,您使用的是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"
,其他未受保护的视频适用于所有设备。