Is there anyway to get metadata of an mp3 file using php? Even just the track length. Thanks.

Recommended Answers

All 2 Replies

The format of MP3 isn't as difficult as one might think at first time. Information like title, author, album etc are simple string stored at the end of the file. This section always starts with "ID3".
To get the length of the song you need various information. The number of tracks (eg mono, stereo, surround), the frequency used and so on. Then you have to skip through the so called "blocks", read the current compression rate (not all MP3s are encoded with a constant bitrate), add them all together and divide by a quotient of the stuff you found out at the beginning.
Personally, I never did that in PHP, but I used some of these files to figure it out: http://www.wotsit.org/list.asp?page=3&fc=12&search=&al=
It might be quite fuzzy at the beginning, but keep going. Once you understood the basics of MP3, you'll get on very quickly. I think it took me about 3hrs to understand the framework of MP3 - the coding stuff was then about just half an hour.

Greetings Simon

thanks alot for the link.. i didn't really get what by what you explained but i'll try to understand more about mp3.. maybe i can get some knowledge from it..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.