Skip to content

Instantly share code, notes, and snippets.

@aindong
Created November 21, 2018 15:20
Show Gist options
  • Save aindong/5d273cadad9ff23e7b9b6794e9b438c8 to your computer and use it in GitHub Desktop.
Save aindong/5d273cadad9ff23e7b9b6794e9b438c8 to your computer and use it in GitHub Desktop.
Get local video duration using promise
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