Skip to content

Instantly share code, notes, and snippets.

@speir-wang
Last active November 11, 2022 03:46
Show Gist options
  • Save speir-wang/b43f38b467a5d66b56073ea7cd08831a to your computer and use it in GitHub Desktop.
Save speir-wang/b43f38b467a5d66b56073ea7cd08831a to your computer and use it in GitHub Desktop.
Avoid the HTML5 video play button being displayed automatically on iPhone when the Low Power mode is turned on.
let videoBackground = document.getElementById("video-background");
var promise = videoBackground.play();
if (promise !== undefined) {
promise
.catch(error => {
// Auto-play was prevented
// Show a UI element to let the user manually start playback
console.log(error);
})
.then(() => {
// if there is no error, then we play the video
videoBackground.play();
});
}
@DepressedUnicorn
Copy link

did not work for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment