Skip to content

Instantly share code, notes, and snippets.

@Sandip124
Forked from andreupifarre/preload-it-example.js
Created December 13, 2019 10:59
Show Gist options
  • Save Sandip124/10bebdedc94b92e0352b30bc01a74c2c to your computer and use it in GitHub Desktop.
Save Sandip124/10bebdedc94b92e0352b30bc01a74c2c to your computer and use it in GitHub Desktop.
const preload = Preload();
preload.fetch([
'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerEscapes.mp4',
'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerFun.mp4',
'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4'
]).then(result => {
// use either a promise or 'oncomplete'
});
preload.oncomplete = items => {
player.src = preload.getItemByUrl('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerFun.mp4').blobUrl;
player.play();
}
preload.onprogress = event => {
document.getElementById('progress').textContent = document.getElementById('progress-bar').style.width = event.progress + '%';
}
preload.onfetched = item => {
document.getElementById('loaded-items').innerHTML += '<span>' + item.fileName + ' <strong>[' + item.size + ']</strong></span>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment