jQuery Simple Example
HTML
<script src="//www.addressfinder.co.nz/assets/v2/widget.js"></script>
<video id="video" width="200" height="200" controls>
<source id='currentVID' src="" type="video/mp4">
</video>
CSS
video.loading {
background: black url(http://blog.teamtreehouse.com/wp-content/uploads/2015/05/InternetSlowdown_Day.gif) center center no-repeat;
}
JavaScript
const actualvideo = 'https://api-files.sproutvideo.com/file/7c9adbb51915e2cdf4/b6e4822661adad1aremovethis/240.mp4';
const video = document.getElementById('video');
video.addEventListener('canplaythrough', video.play)
if (actualvideo !== '') {
const source = document
.getElementById('currentVID');
const retryDelay = 5000
let retries = 4;
source.addEventListener('error', onSourceErr);
video.pause();
source.setAttribute('src', actualvideo);
video.appendChild(source);
function onSourceErr(){
if (retries) {
setTimeout( function retry(){
video.appendChild( source );
}, retryDelay);
// F12 or Ctrl-Shift-I to open DevTools
// Much more useful than alerts.
console.log( 'Failed to load video, ' +
'retrying ' + (retries) + ' more times' )
retries--
}
else console.log('Something went wrong');
}
}
// mimick network recovery by sneaking a cat in the back door
setTimeout(function mockRecovery(){
document.getElementById('currentVID')
.setAttribute('src', 'https://ak0.picdn.net/shutterstock/videos/8191870/preview/stock-footage-cat-with-big-eyes.mp4')
}, 12000)