Skip to content

Instantly share code, notes, and snippets.

@aferriss
Created July 25, 2018 20:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aferriss/99dc65bbc079e28f95030ff34e5a161b to your computer and use it in GitHub Desktop.
Save aferriss/99dc65bbc079e28f95030ff34e5a161b to your computer and use it in GitHub Desktop.
Load a Video with Promise
module.exports = {
videos : function(asset){
return new Promise(function(resolve, reject){
var vElement = document.createElement('video');
vElement.autoplay = true;
vElement.muted = true;
vElement.loop = true;
vElement.playsinline = true;
vElement.playsInline = true;
vElement.src = asset.url;
vElement.controls = true;
vElement.name = asset.name;
vElement.load();
vElement.addEventListener('canplaythrough', function(){
console.log(asset);
resolve(vElement);
});
vElement.addEventListener('error', function(){
reject(vElement);
});
})
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment