Skip to content

Instantly share code, notes, and snippets.

@tai2
Last active January 30, 2019 06:50
Show Gist options
  • Save tai2/d456299d66c69f96f180b929d4832219 to your computer and use it in GitHub Desktop.
Save tai2/d456299d66c69f96f180b929d4832219 to your computer and use it in GitHub Desktop.
export default function getVideoDuration(src: string): Promise<number> {
return new Promise((resolve, reject) => {
const video = document.createElement('video')
video.src = src
video.addEventListener('loadedmetadata', () => {
resolve(video.duration)
})
video.addEventListener('error', error => {
reject(error)
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment