Created
March 4, 2020 20:15
-
-
Save humphd/3738c6f0536079b3889d212402710f92 to your computer and use it in GitHub Desktop.
Event Example from WEB222
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
window.onload = function() { | |
let src = 'https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp4' | |
document.body.addEventListener('click', function() { | |
// Create a source element | |
let source = document.createElement('source'); | |
// Set its src to be our video URL | |
source.src = src; | |
// Grab the video element and add the source to it | |
let video = document.querySelector('video'); | |
video.width = 800; | |
video.setAttribute('width', '800'); | |
video.appendChild(source); | |
document.addEventListener('visibilitychange', function() { | |
if(document.hidden) { | |
document.title = 'paused'; | |
video.pause(); | |
} else { | |
document.title = 'playing'; | |
video.currentTime = 0; | |
video.play(); | |
} | |
}); | |
// Start video playing... | |
video.play(); | |
document.title = 'playing'; | |
setInterval(function() { | |
document.title = video.currentTime; | |
}, 1000); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment