I'm developing a web app for iOs device, but I have a problem with the html5 audio tag... I designed a custom audio player, and I control the song with javascript functions. With safari desktop the app works well, but on safari mobile it doesn't recognize the duration of the audio; the value of the duration property is NaN. I have to play, stop and replay the audio for retrieve the correct value. Probably the cause is that the media preload is disabled on safari mobile... Is there a way to read the correct value at the first shot?
Asked
Active
Viewed 4,818 times
6
-
Theree was some js event telling when audio metadata is available. Did you try it? – Mikko Ohtamaa Sep 01 '11 at 00:26
-
thanks... I solved the problem adding a listener to the "onloadedmetadata" event; when the meta are loaded, I call a set-up function. – diegocstn Sep 01 '11 at 19:45
2 Answers
9
This is a bug in iOS... even inside the function that gets called on the onloadedmetadata
event, you MAY STILL get NaN
.
In my case, this happens at random when the user selects a new mp3 and the code dynamically sets the src
property. The audio plays fine, yet SOMETIMES, the duration returns NaN
, screwing up any progress indicator that depends on that value.
2
The medata is available after this event has fired:
loadedmetadata
More info
https://developer.mozilla.org/en/Introducing_the_Audio_API_Extension

Mikko Ohtamaa
- 82,057
- 50
- 264
- 435
-
For me it was the `loadedmetadata` event. https://developer.mozilla.org/en-US/docs/Web/Events/loadedmetadata – Andrey Mikhaylov - lolmaus Nov 14 '14 at 10:28
-
-