Youtubeembedded式video:自动播放function不工作在iPhone

我有一个YouTube的embedded式video链接在HTML5页面,我想自动播放

下面的代码在浏览器中工作,但在iphone中; 它不工作,需要额外的点击。

<iframe type="text/html" width="125" height="100" src="http://www.youtube.com/embed/d_g0251EfB8?autoplay=1" frameborder="0"></iframe> 

该怎么办

这是不能做到的。 由于各种原因(包括但不限于数据使用),Apple不允许自动播放video。

看到这个问题的答案 。

我已经尝试使用以下和Youtubevideo成功自动播放全屏幕时,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]]; 

更新:

iOS 10+现在允许在HTML5 <video>元素上自动播放,只需要将元素上的audio静音即可。 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/

Interesting Posts