Detect youtube iframe autoplay failure

天大地大妈咪最大 提交于 2019-12-23 02:16:25

问题


iOS and Android only allow playing a video inside a callback of a user interaction. Chrome 66 introduced the autoplay policy.

How can we detect that embedded youtube iframe failed to autoplay a video so we can play it muted and show 'tap to unmute' button?

The API has onError callback but it's not clear if and what error will fire. This is also hard to test because of Chrome's Media Engagement Index.

HMTL 5 video autoplay failure can be detected. Is there an equivalent in the YouTube iframe API?

var promise = document.querySelector('video').play();

if (promise !== undefined) {
  promise.then(_ => {
    // Autoplay started!
  }).catch(error => {
    // Autoplay was prevented.
    // Show a "Play" button so that user can start playback.
  });
}

Thanks

来源:https://stackoverflow.com/questions/50080974/detect-youtube-iframe-autoplay-failure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!