audio5js icon indicating copy to clipboard operation
audio5js copied to clipboard

duration is broken

Open lolmaus opened this issue 10 years ago • 13 comments

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.

dafuq

lolmaus avatar Nov 11 '14 13:11 lolmaus

Chrome Version 38.0.2125.111 (64-bit)

lolmaus avatar Nov 11 '14 13:11 lolmaus

Audio5js release: 3c45ae2b74

lolmaus avatar Nov 11 '14 13:11 lolmaus

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 avatar Nov 11 '14 15:11 lolmaus

@lolmaus sorry for the late reply - Is everything working then or do you need my assistance with something?

zohararad avatar Nov 12 '14 16:11 zohararad

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.

lolmaus avatar Nov 12 '14 16:11 lolmaus

@zohararad ran into this problem anyway you'll be fixing this?

SJAnderson avatar May 13 '15 23:05 SJAnderson

@SJAnderson on safari mobile?

zohararad avatar May 14 '15 03:05 zohararad

@zohararad @SJAnderson @lolmaus I will look into this one later.

belldandu avatar Nov 21 '15 06:11 belldandu

I also encountered this problem, hope to be able to fix

anrananran avatar Nov 27 '15 03:11 anrananran

Same here, in Safari on Mac. Per OP's resolution I'll probably switch to vanilla <audio> as well.

valrus avatar Jun 21 '17 22:06 valrus

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.)

valrus avatar Jun 26 '17 03:06 valrus

Update: Adding that header did indeed fix things with both vanilla audio and audio5js. Hope this helps someone somewhere down the line.

valrus avatar Jun 26 '17 04:06 valrus

@valrus thanks for this update - very much appreciated!

zohararad avatar Jun 26 '17 04:06 zohararad