So recently, I submitted a bid on a project to make a lyrics website using
PHP. I haven’t been contacted about whether or not I won the bid yet, but I decided that I might
as well start some preliminary work on backend coding – It’ll make my life easier, and deliver a faster and
better result to the client, so why not?
Why am I mentioning this, you ask?
What does my personal life have to do with my tech blog? Well, I’m getting to that!
I
almost immediately thought. “Hey, wouldn’t it be really cool if the admin of the website could
simply upload an MP3 file and pull almost, if not all of the data from it to use on the site?” After which,
I quickly searched around for something that would allow me to do just that, to read the ID3 tags on an MP3
file.
The first thing I came to, was the search result on the PHP website for “id3,” the
ID3 PECL Library.
Unfortunately, after trying for a very long time on DreamHost, I not only couldn’t get it to install, but
had just wasted probably an hour in an attempt to. Not only that, but the library was still in its
alpha stage.
Some quick internet searching took me to the href="http://getid3.sourceforge.net/">getid3 library, a robust library programmed to read ID3
data tags (and other types of metadata?) from almost any type of file. I quickly set about to
using it, and found its internal structure complicated and confusing. It didn’t even offer me a
quick and easy way to access the album artwork.
After a good period of time learning some
of the basic structure of ID3 and how the getid3 library worked, I set about to coding up a library of my
own to quickly interface with getid3 and retrieve the information I needed.
The result is
class::mp3Data. A very, very simple library
built exclusively to interface with getid3 and retrieve basic information about an mp3 file while still
retaining more advanced information for coders who need it. Take a look at some example code and
the licensing permissions after the break.
src="http://i.creativecommons.org/l/by-nc-sa/3.0/us/80x15.png" />
Retrieving and Displaying the Artwork as a Picture:
style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom:4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%;
padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr;
max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right:
silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
1:
<?php
style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt;
border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%;
padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr;
border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible;
padding-top: 0px"> 2: require_once("mp3Data.class.php");
3: $data = style="color: #0000ff">new mp3Data("filename.mp3");
4: $img = $data->getArt();
5: if ($img)
style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt;
border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%;
padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr;
border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible;
padding-top: 0px"> 6: {
7: header( style="color: #006080">"Content-type: image/jpeg");
8: imagejpeg($img);
9: }
10: ?>
[...] Code is located at pastebin and retains the same usage permissions as v0.1.
ReplyDelete[...]
I found this very helpful, thank you!
ReplyDeleteHi! Very useful, thanks for your colla bro.
ReplyDeleteIm using it and works
perfectly, thanks bro. But, can you create a set of setters aside from the getters?
Hope
you can :D
I'm having some problems displaying the image, can you help me? Is that jpeg image
ReplyDeleteformat displaying way for every id3Tags for each mp3?
We have sell some products of different custom boxes.it is very useful and very low price please visits this site thanks and please share this post with your friends. tubidy mp3
ReplyDeleteBy the age of 11, there appeared to be little that any music educator could show George; it was now that George's dad started furious and again communicated his longing for George to stop playing in the music, and to come all the way back and do as he wished. https://many-ringtones.com/13245-michigan-marching-band-lets-go-blue.html Michigan Marching Band Lets Go Blue Ringtone
ReplyDelete