showing results for - "javascript audio duration property returns infinity"
Fynn
06 Mar 2020
1var getDuration = function (url, next) {
2    var _player = new Audio(url);
3    _player.addEventListener("durationchange", function (e) {
4        if (this.duration!=Infinity) {
5           var duration = this.duration
6           _player.remove();
7           next(duration);
8        };
9    }, false);      
10    _player.load();
11    _player.currentTime = 24*60*60; //fake big time
12    _player.volume = 0;
13    _player.play();
14    //waiting...
15};
16
17getDuration ('/path/to/audio/file', function (duration) {
18    console.log(duration);
19});