7 Replies - 24712 Views - Last Post: 26 December 2011 - 08:12 AM

#1 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 180
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

Calculating Length of a Song stored in MP3 Format

Posted 07 November 2008 - 11:14 AM

Does anybody know how to find the length of a song (i.e. duration, not file size) from an mp3 file?

I've tried looking everywhere (MP3 Headers, ID3 Tag Formats) but I can't seem to find anything about the song duration. I guess I'm not looking at the right places.

The only thing I could gather from whatever I read is that the duration is stored in milliseconds.

Is there any way to calculate the song duration from an mp3 file? (Any Language will do)

Thanks in Advance.

Is This A Good Question/Topic? 0
  • +

Replies To: Calculating Length of a Song stored in MP3 Format

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1637
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Calculating Length of a Song stored in MP3 Format

Posted 07 November 2008 - 11:24 AM

Hey B2C, check out this article, I think it may help. It's in C# by the way
Was This Post Helpful? 0
  • +
  • -

#3 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 180
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

Re: Calculating Length of a Song stored in MP3 Format

Posted 07 November 2008 - 11:32 AM

aWsm, that's just what I needed Psycho!
I haven't tested the code yet but it should work.
Thanks.
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1637
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Calculating Length of a Song stored in MP3 Format

Posted 07 November 2008 - 11:33 AM

No problem, glad I could help :)
Was This Post Helpful? 0
  • +
  • -

#5 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 180
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

Re: Calculating Length of a Song stored in MP3 Format

Posted 07 November 2008 - 11:37 AM

...and it works fine.
Thanks again.
:)
Was This Post Helpful? 0
  • +
  • -

#6 ehudbk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 22-August 10

Re: Calculating Length of a Song stored in MP3 Format

Posted 22 August 2010 - 08:35 AM

hello, I have the same problem but the article is no longer available.
Do you by any chance have the acrticle saved anywhere?

Thanks,

Ehud
Was This Post Helpful? 0
  • +
  • -

#7 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2233
  • View blog
  • Posts: 9,401
  • Joined: 29-May 08

Re: Calculating Length of a Song stored in MP3 Format

Posted 22 August 2010 - 11:48 AM

Saved page at web.archive.org
Was This Post Helpful? 1
  • +
  • -

#8 111027  Icon User is offline

  • D.I.C Head

Reputation: 17
  • View blog
  • Posts: 141
  • Joined: 26-December 11

Re: Calculating Length of a Song stored in MP3 Format

Posted 26 December 2011 - 08:12 AM

I do not have the article, nor while i put code here, but here's the general idea:

A sound file is encoded by length. Most mp3 files use up 128 or 256 kilobits of memory to store a singe second of data (audio). That number is in the file description, which you could easily obtain using a proper API to your operating system. Also, you'll need the total filesize, which is also obtainable. Now, the last step? Divide the filesize by the bit rate, and you have the length of the song.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1