audio5js
audio5js copied to clipboard
duration is broken
Hi!
I'm trying to retrieve the duration of a track, following the Mobile Safari usage pattern.
Inside a canplay
event callback i access player.duration
property, and it always returns 0.
From play button click callback, the player.duration
is 0 for the first time and 30.000181
on subsequent tries, which seems to be the correct value.
But i've also seen player.duration
return 0:30
and NaN:NaN
.
Chrome Version 38.0.2125.111 (64-bit)
Audio5js release: 3c45ae2b74
I have refactored my code to use native <audio>
instead of audio5js, and player.duration
returns 30.000181
from the canplay
callback. I never see 0
returned.
PS Thank you for the Mobile Safari pattern. I've modified it to use a promise and it's very convenient. I would hardly make it that good without your example.
@lolmaus sorry for the late reply - Is everything working then or do you need my assistance with something?
Due to the described bug, I abandoned audio5js in favor of vanilla HTML5 <audio>
API. It works for me and I don't need help, but the initial problem with audio5js duration
still stands.
@zohararad ran into this problem anyway you'll be fixing this?
@SJAnderson on safari mobile?
@zohararad @SJAnderson @lolmaus I will look into this one later.
I also encountered this problem, hope to be able to fix
Same here, in Safari on Mac. Per OP's resolution I'll probably switch to vanilla <audio>
as well.
Small update, for anyone who runs into this in Safari: I have a hunch that it's because of the issue in this SO question: https://stackoverflow.com/questions/1995589/html5-audio-safari-live-broadcast-vs-not
In particular, it looks like your server needs to be able to respond "appropriately" to Range
requests, which you can do by adding a Content-Range
header. I checked and the server I'm using for testing things (python 3's built in python -m http.simple
) doesn't include that header. (I switched to vanilla <audio>
and it didn't solve this for me, so it's not clear how it did so for lolmaus, but if adding that header to my server fixes this, I'll report back here.)
Update: Adding that header did indeed fix things with both vanilla audio and audio5js. Hope this helps someone somewhere down the line.
@valrus thanks for this update - very much appreciated!