Skip to content

Instantly share code, notes, and snippets.

@humphd
Created March 4, 2020 20:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save humphd/3738c6f0536079b3889d212402710f92 to your computer and use it in GitHub Desktop.
Save humphd/3738c6f0536079b3889d212402710f92 to your computer and use it in GitHub Desktop.
Event Example from WEB222
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