Skip to content

Instantly share code, notes, and snippets.

@hassanuos
Created April 4, 2024 11:28
Show Gist options
  • Save hassanuos/7c971da2cba4a65635a85784f8d5a6c1 to your computer and use it in GitHub Desktop.
Save hassanuos/7c971da2cba4a65635a85784f8d5a6c1 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<script>
function handleVisibilityChange() {
let videoSelector = document.querySelector('video');
if(document.hidden) {
videoSelector.pause();
console.log('Video Paused!!!!');
} else {
videoSelector.play();
console.log('Video Played!!!!');
}
}
document.addEventListener("visibilitychange", handleVisibilityChange, false);
</script>
<body>
<h1>The video element</h1>
<video width="320" height="240" controls>
<source src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" type="video/mp4">
</video>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment