Created
November 21, 2018 15:20
-
-
Save aindong/5d273cadad9ff23e7b9b6794e9b438c8 to your computer and use it in GitHub Desktop.
Get local video duration using 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
const getDuration = file => { | |
return new Promise((resolve, reject) => { | |
let videoElement = document.createElement("video"); | |
videoElement.preload = "metadata"; | |
videoElement.onloadedmetadata = function() { | |
window.URL.revokeObjectURL(videoElement.src); | |
resolve(videoElement.duration); | |
}; | |
videoElement.src = window.URL.createObjectURL(file); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment