I'm using jPlayer to show an audio player for mp3 files, and the duration field shows 00:00
until I hit the play button, and then it shows the correct duration while playing. (Note that this is a different symptom than in this similar question.)
How can I get jPlayer to pick up and display the duration before the user hits the play button (so they know how long the audio clip is before deciding to play it)? Thanks.
It turns out that jPlayer supports the HTML5 preload
argument, such that adding preload: 'auto'
to the jPlayer constructor options fixes this problem and displays the track duration. However, this also downloads the whole audio file, which is annoying, because it can use a lot of bandwidth for an audio track that the user may never play. And it's even worse in my case, because I've got a page with a dozen user stories, and the page downloads all of them.
Frustratingly, there's an option preload: 'metadata'
, which sounds like it should do exactly what I want, namely, download the track metadata without downloading the whole file, but this doesn't seem to work. This is apparently something that browsers should support, but don't yet.
For now, I'll either skip this feature, or build a server side piece to check the duration and stream it via separate AJAX call.