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