admin管理员组文章数量:1426338
So I cannot autoplay a YouTube video due to this update which prevents videos that aren't muted from playing on mobile:
I've tried setting mute=1
and volume=0
in my Video URL. The mute parameters does successfully mute the video on Desktop, but I still cannot get the video to autoplay on mobile. The reason I need autoplay to work is because I am loading an image of the video on the initial page load. Once the user clicks the video, my JavaScript loads the iframe. This significantly helps the performance of my page. There are several other questions on Stack Overflow that are related but none of the answers have worked.
Here is my current code:
<iframe width="560" height="315" src=";mute=1" volume="0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
So I cannot autoplay a YouTube video due to this update which prevents videos that aren't muted from playing on mobile: https://developers.google./web/updates/2017/09/autoplay-policy-changes
I've tried setting mute=1
and volume=0
in my Video URL. The mute parameters does successfully mute the video on Desktop, but I still cannot get the video to autoplay on mobile. The reason I need autoplay to work is because I am loading an image of the video on the initial page load. Once the user clicks the video, my JavaScript loads the iframe. This significantly helps the performance of my page. There are several other questions on Stack Overflow that are related but none of the answers have worked.
Here is my current code:
<iframe width="560" height="315" src="https://www.youtube./embed/QHfgMrpMOm4?autoplay=1&mute=1" volume="0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
Share
Improve this question
asked Feb 5, 2019 at 0:04
Cannon MoyerCannon Moyer
3,1844 gold badges37 silver badges83 bronze badges
1
- 2 you can check this answer in ios the autoplay not going to work without the user interaction. stackoverflow./questions/15090782/… – Chilll007 Commented Feb 5, 2019 at 7:17
1 Answer
Reset to default 3Had same issue, looks like something changed. Only solution, that worked for me was - use youtube API
var tag = document.createElement('script');
tag.src = "https://www.youtube./iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
videoId: 'M7lc1UVf-VE',
events: {
'onReady': onPlayerReady,
}
});
}
function onPlayerReady(event) {
event.target.mute();
event.target.playVideo();
}
<!DOCTYPE html>
<html>
<body>
<div id="player"></div>
</body>
</html>
本文标签: javascriptCannot autoplay YouTube on mobile devicesStack Overflow
版权声明:本文标题:javascript - Cannot autoplay YouTube on mobile devices - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745447870a2658745.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论