Skip to content

Instantly share code, notes, and snippets.

@itamar
Created December 28, 2015 15:40
Show Gist options
  • Select an option

  • Save itamar/776cbce541133ed684e5 to your computer and use it in GitHub Desktop.

Select an option

Save itamar/776cbce541133ed684e5 to your computer and use it in GitHub Desktop.
Find audio file duration
audioElement = document.createElement('audio');
audioElement.setAttribute('src', MP3_URL_GOES_HERE);
audioElement.load();
console.log('Loading audioElement');
audioElement.addEventListener('canplaythrough', function(){
console.log('audioElement Loaded');
console.log('Duration in seconds: ' + this.duration);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment