JavaScript Audio duration returns NaN need some modification to run the player audio duration returns nan

It is always advised to use the event of loadedmetadata and then calling them will always work. Using Event Listeners are best in this case.

var a = document.getElementById('mytrack');
a.addEventListener("loadedmetadata", function() {
  var duration1 = document.getElementById('fullDuration');
  duration1.innerHTML = parseInt(a.duration);
}, true);

This waits till the media is loaded and then it sets the contents of the <span> tag. For best results, please put this code either in the end of the document, before </body> tag or use window's load event:

document.addEventListener('DOMContentLoaded', function () {
  var a = document.getElementById('mytrack');
  a.addEventListener("loadedmetadata", function() {
    var duration1 = document.getElementById('fullDuration');
    duration1.innerHTML = a.duration;
  }, true);
}, false);

As said in comments, there's also another way to do it using preload attribute:

This enumerated attribute is intended to provide a hint to the browser about what the author thinks will lead to the best user experience.

But since you already haveautoplay attribute, I guess preload won't be necessary.

The autoplay attribute has precedence over preload. If autoplay is specified, the browser would obviously need to start downloading the audio for playback.

Answer:1

I'm building an Angular directive which allows the user to enter a North American phone number in a variety of common formats (such as "1(301) 797-1483" or "301.797.1483"), but stores it internally as ...

I'm building an Angular directive which allows the user to enter a North American phone number in a variety of common formats (such as "1(301) 797-1483" or "301.797.1483"), but stores it internally as ...

Using regex I am attampting to limit the user's input to one of the following scenarios: http(s)://www.instagram.com/user www.instagram.com/user http(s)://instagram.com/user instagram.com/user ...

Using regex I am attampting to limit the user's input to one of the following scenarios: http(s)://www.instagram.com/user www.instagram.com/user http(s)://instagram.com/user instagram.com/user ...

I am trying to sign my app-unsigned.apk with build.json. I created the keystore through console and my build.json has: { "android": { "debug": { "keystore": "C:\\\\Users\\Matteo....

I am trying to sign my app-unsigned.apk with build.json. I created the keystore through console and my build.json has: { "android": { "debug": { "keystore": "C:\\\\Users\\Matteo....

I'm trying to wait for a bunch of promises to complete. I know I can do this with Promise.all, but I can't figure out what to do when one of those promises pushes a new promise into the promise list. ...

I'm trying to wait for a bunch of promises to complete. I know I can do this with Promise.all, but I can't figure out what to do when one of those promises pushes a new promise into the promise list. ...

  1. recursive promise chain
  2. recursive promise nodejs
  3. recursive promise chain javascript
  4. recursive promises js
  5. recursive promise.all
  6. recursive promise function
  7. recursive promise typescript
  8. recursive promise memory leak
  9. recursive promise resolve
  10. recursive promise example
  11. recursive promise then
  12. recursive promise loop
  13. recursive promise angular
  14. recursive promises angularjs
  15. recursive promise swift
  16. recursive promise return
  17. recursive promise chain js
  18. recursive promise es6
  19. recursive promise async
  20. recursive promise stack overflow