Why does the second one return NaN?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why does the second one return NaN??

They are both audio....they are the same but other returns NaN when I want duration https://code.sololearn.com/W1F8lzcQ7Cfs/?ref=app

30th Jul 2023, 4:57 PM
Indiphile Menziwa
Indiphile Menziwa - avatar
4 Answers
+ 4
It might be to do with timing. Perhaps the length of the song is too long for the time it takes to figure out the duration, or something similar. You could test that theory with a song that's like 1 minute long, see if it still shows NaN
30th Jul 2023, 5:07 PM
Ausgrindtube
Ausgrindtube - avatar
+ 4
Here is a list of audio events. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio#events I'm sure one of them will help solve your problem. Maybe loadeddata or loadedmetadata
31st Jul 2023, 10:51 AM
ODLNT
ODLNT - avatar
+ 1
Yes you're somewhat right. So it turns out the reason is because it the sound was still loading into the project and because of this it's longer length it takes abit longer for it to be added, so it reads before it's added and finds nothing. So I just have to make sure js reads the code after its loaded in, I already have windows.onload for the whole code which I assume would work but I'll have to bring another approach more specific to the element audio rather than just window.onload...
30th Jul 2023, 6:01 PM
Indiphile Menziwa
Indiphile Menziwa - avatar
+ 1
Indiphile Menziwa When your code have to be executed in relation to the audio?
30th Jul 2023, 7:27 PM
KrOW
KrOW - avatar