1

HTML5 audio.duration calculates the wrong duration because it doesn't exclude the stuff before the header like id3-tag with artwork.

If you add artwork to your file this can be multiple seconds.

I read about the Content-Length HTTP response header but I write a script where you drag'n'drop local files so that won't help much.

Can I calculate the duration myself without HTML5? If HTML5 can calculate it from the bytes and frames (?) it should be possible to do it better.

Martin
  • 2,007
  • 6
  • 28
  • 44
  • Can't you get the duration from server-side? If yes, try sox: http://stackoverflow.com/questions/10437750/how-to-get-the-real-actual-duration-of-an-mp3-file-vbr-or-cbr-server-side?rq=1 – huysentruitw Jun 30 '13 at 05:44
  • I want to drag'n'drop local files to receive file info like duration, bitrate and file size. I only managed to receive the file size by now tho. The files are large (50 MB - 500 MB) so uploading them first would be unhandy. – Martin Jun 30 '13 at 12:51
  • Can you access file data at client side? If yes then you can do it yourself. For CBR encoded files it's simple but for VBR encoding, you'll need to read the info of each frame if you want the exact duration. – huysentruitw Jul 01 '13 at 05:20
  • VBR: Yes, it's hard, also to get the correct average bitrate then. I fear javascript cannot do that. "Can you access file data at client side?" > What do you mean? I want to fill a form on my website with the file info so people would drag'n'drop the file into the browser. – Martin Jul 01 '13 at 10:53
  • Example drag'n'drop with HTML duration: http://jsfiddle.net/H7xFS/2/ - The problem: When you download e.g. http://daten.clr.net/pod/CLRSR224_dense_&_pika.mp3 and drop it, it reads 61:20 minutes instead of proper 61:08 because it has a 275 KB artwork included. – Martin Jul 01 '13 at 11:02
  • You may find your solution here: http://stackoverflow.com/questions/383164/how-to-retrieve-duration-of-mp3-in-net/13269914#13269914 – John Pankowicz Jul 02 '13 at 21:52

0 Answers0