gpt4 book ai didi

javascript - YouTube iframe API 不自动播放

转载 作者:行者123 更新时间:2023-11-30 14:35:28 25 4
gpt4 key购买 nike

我无法让 YouTube Iframe API 自动播放视频。您可以在此处查看我的部分代码,并在下面的 Codepen 链接中查看完整代码。

<!-- language: lang-js -->
window.onYouTubeIframeAPIReady = function() {
let player;

player = new YT.Player('player', {
height: '200',
width: '360',
videoId: videoId,
suggestedQuality: 'hd720',
events: {
'onReady': event => {
event.target.playVideo();
}
},
playerVars: config
});
}

查看我的 Codepen

最佳答案

自动播放仅适用于某些要求。 Chrome 中有一个新的自动播放策略:https://developers.google.com/web/updates/2017/09/autoplay-policy-changes

Chrome's autoplay policies are simple:

  • Muted autoplay is always allowed.
  • Autoplay with sound is allowed if:
    • User has interacted with the domain (click, tap, etc.).
    • On desktop, the user's Media Engagement Index threshold has been crossed, meaning the user has previously play video with sound.
    • On mobile, the user has added the site to his or her home screen.
  • Top frames can delegate autoplay permission to their iframes to allow autoplay with sound.

Media Engagement Index (MEI)

The MEI measures an individual's propensity to consume media on a site. Chrome's current approach is a ratio of visits to significant media playback events per origin:

  • Consumption of the media (audio/video) must be greater than 7 seconds.
  • Audio must be present and unmuted.
  • Tab with video is active.
  • Size of the video (in px) must be greater than 200x140.

如果您想确保视频始终播放,只需将其静音即可。

关于javascript - YouTube iframe API 不自动播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50495493/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com