我有一个YouTube视频链接在HTML5页面,我想要autoplay。Youtube嵌入的视频:自动播放功能不工作在iphone
以下代码适用于浏览器,但在iphone中;它不工作,需要额外的点击。
<iframe type="text/html" width="125" height="100" src="http://www.youtube.com/embed/d_g0251EfB8?autoplay=1" frameborder="0"></iframe>
做什么
我有一个YouTube视频链接在HTML5页面,我想要autoplay。Youtube嵌入的视频:自动播放功能不工作在iphone
以下代码适用于浏览器,但在iphone中;它不工作,需要额外的点击。
<iframe type="text/html" width="125" height="100" src="http://www.youtube.com/embed/d_g0251EfB8?autoplay=1" frameborder="0"></iframe>
做什么
它不能这样做。由于各种原因(包括但不限于数据使用),Apple不允许自动播放视频。
我试图与以下和YouTube视频自动播放成功在全屏时,Web视图加载完成:
[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 id='playerId' type='text/html' width='100%%' height='%f' src='http://www.youtube.com/embed/%@?enablejsapi=1&rel=0&playsinline=0&autoplay=1' frameborder='0'allowfullscreen>\
</body>\
</html>",self.webView.frame.size.height,@"Dw9jFO_coww"];
[self.webView bringSubviewToFront:self.btnBack];
self.webView.backgroundColor = [UIColor clearColor];
self.webView.opaque = NO;
[self.webView loadHTMLString:embedHTML baseURL:[[NSBundle mainBundle] resourceURL]];
代码是填写错别字,并缺乏清晰度:(哦,它的坏) –
OP是要求HTLM5不是ObjC,不? –
UPDATE:
的iOS 10+现在允许在HTML5自动播放视频<>元素,只需要静音元素上的音频。 Youtube将不会。 Android仍然是SOL,但嘿,它是一个开始!
示例:
<video autoplay muted>
<source src="movie.mp4" type="video/mp4">
Sadly, your browser does not support the video tag X_x
</video>
信息来源:https://webkit.org/blog/6784/new-video-policies-for-ios/
thnaks。让我删除我的问题 –
@AvisekChakraborty:请不要删除它。即使答案不符合你的期望,这仍然是有用的信息。 –
是的。我当然不会删除它。 thnx –