Created
July 25, 2018 20:06
-
-
Save aferriss/99dc65bbc079e28f95030ff34e5a161b to your computer and use it in GitHub Desktop.
Load a Video with Promise
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
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