我一直在寻找解决方案的好时机。视频可以自动播放并在浏览器上循环播放。但是在iPhone或iPad上无法正常工作。
<div id="about-player"></div>
<script>
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('about-player', {
videoId: 'ZyYGXrfeoK8',
playerVars: {
modestbranding: 0,
autoplay: 1,
controls: 0,
showinfo: 0,
wmode: 'transparent',
branding: 0,
rel: 0,
autohide: 0,
playlist: 'ZyYGXrfeoK8',
inline: 1,
origin: window.location.origin
},
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function onPlayerReady(event) {
event.target.playVideo();
}
var done = false;
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING && !done) {
setTimeout(stopVideo, 300000);
done = true;
}
}
function stopVideo() {
player.stopVideo();
}
</script>
是否可以在IOS设备上自动播放youtube视频?如果是这样,我需要对代码进行哪些更改,以实现此目的。