我有一個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 –