Created
March 6, 2020 08:16
-
-
Save mileskrell/700c1207217e0f9626b405fbd5d7992a to your computer and use it in GitHub Desktop.
Try to detect if autoplay on videos is blocked
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<video id="vid" autoplay loop muted> | |
<source src="/vid.mp4" type="video/mp4" /> | |
</video> | |
<script> | |
setTimeout(function() { | |
let vid = document.getElementById("vid"); | |
if (vid.paused) { | |
let message = document.createElement("p"); | |
message.innerHTML = "There's supposed to be a video here, but your browser either " + | |
"doesn't support the video element or is blocking autoplay"; | |
vid.replaceWith(message); | |
} | |
}, 100); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment