Created
January 6, 2017 12:31
-
-
Save JustinDFuller/ab65954961d76f15d8a273c99577d20b to your computer and use it in GitHub Desktop.
Change video src based on loading times.
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
let loadingTimes = 0; | |
const maxLoadingTimesBeforeChange = 4; | |
const videoOptions = { | |
hd: 'myAwesomeVideoHD.mp4', | |
sd: 'myAwesomeVideoSD.mp4', | |
}; | |
const video = `<video id='myVideo' src=${videoOptions.hd}></video>`; | |
const videoContainer = document.getElementById('myVideoContainerID'); | |
videoContainer.innerHTML = video; | |
const videoElement = document.getElementById('myVideo'); | |
videoElement.onstalled = loading; | |
videoElement.onwaiting = loading; | |
function loading () { | |
loadingTimes++; | |
if (loadingTimes > maxLoadingTimesBeforeChange) { | |
videoElement.setAttribute('src', videoOptions.sd); | |
videoElement.load(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment