javascript - YouTube 自动播放在 Chrome 中不起作用

标签 javascript google-chrome youtube autoplay

一段时间以来,我一直在使用这个脚本,视频自动全屏播放。现在突然之间,视频无法在 Chrome 中自动播放。但在 Firefox 和 Edge 中它仍然有效。

所以也许 Google 更改了设置?请问有人知道如何解决这个问题吗? 您可以在此处查看现场示例:www.brunomazereel.com

<script src="http://www.youtube.com/player_api"></script>
<script type="text/javascript">
var player;
function onYouTubePlayerAPIReady() {
    player = new YT.Player('player', {
    playerVars: {
        'autoplay': 1,
        'controls': 0,
        'autohide': 1,
        'wmode': 'opaque',
        'showinfo': 0,
        'loop': 1,
        'rel': 0,
        'playlist': 'rh5QiehIlVA,Bl63bdR-Ko0,'
        },
    videoId: 'u-cjliof1xk',
    events: {
        'onReady': onPlayerReady
    }
});
}
function onPlayerReady(event) {
event.target();
$('#text').fadeIn(400);
}
$(window).scroll(function() {
var hT = $('.m-video').height(),
   wS = $(this).scrollTop();
if (wS > hT) {
  player.pauseVideo();
}
else {
  player.playVideo();
}
});
</script>

最佳答案

(一个)从评论讨论中获得的可能解决方案是将视频静音,如果声音对您而言不是那么重要(如果是,我将离开回答,因为它可以帮助其他人)

这显然是始终 启用自动播放的唯一方法。来自文章:

"Muted autoplay is always allowed."

来源:Google changelog


只需在您的 playerVars 中添加:

mute : 1

Source for the muted video

关于javascript - YouTube 自动播放在 Chrome 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50217075/

相关文章:

javascript - Applescript : wait that the page is load on chrome

youtube - 从 Youtube API 中提取详尽的观看视频列表(>1000 项)

javascript - 视频播放完成后如何显示灯箱?

JavaScript 用 HTML 替换文本不起作用?

javascript - jQuery .html 不适用于 td

javascript - 有没有办法向 Node.js 中的现有主题添加新分区?

javascript - 对表中的多行使用单个可观察对象

CSS3 动画在 Chrome 中不起作用,而在 Firefox 中起作用

javascript - Google 云端硬盘如何知道我安装了哪些应用程序?

actionscript-3 - 无法将YouTube播放器对准Flash CS5(AS3)中的舞台