Hi There, I have mp3 files stored on the iphone and I my application to be able to read the ID3 infomration, i.e length in seconds, artist etc. Anyone know of how to do this or what library to use in objective c?
Your thoughts are much appreciated.
Hi There, I have mp3 files stored on the iphone and I my application to be able to read the ID3 infomration, i.e length in seconds, artist etc. Anyone know of how to do this or what library to use in objective c?
Your thoughts are much appreciated.
This was answered already in this SO question:
http://stackoverflow.com/questions/1138118/how-to-extract-id-tags-from-mp3-files-in-cocoa
There are not many ID3 parsing libraries out there that are not GPLed. There is on Objective-C framework that could probably be modified to work on the iPhone when statically linked, but it is LGPL. In order to satisfy the terms of the LGPL with a statically linked binary you have to provide enough of the intermediary components that someone could relink it with their own version of the library, which is difficult (but not impossible) for an iPhone app. Of course since I have not been in a position where I have had to do that I have not actually discussed it with a lawyer, and since I am not one you should not take that as authoritative.
Your best bet if you don't feel like consulting a lawyer is to use a more liberally licensed C libraray like libID3 and wrap that in some Objective C classes. I would also recommend just directly including the code rather than dealing with all the static library build and link issues, but that is just a personal style thing.
Look into the Media Player framework:
This requires that the MP3 in question is part of the iPod library on the phone.
For example, determining the name of every media file on the phone (including movies, podcasts, etc.):
MPMediaQuery *everything = [[MPMediaQuery alloc] init];
NSArray *itemsFromGenericQuery = [everything items];
for (MPMediaItem *item in itemsFromGenericQuery) {
NSString *itemTitle = [item valueForProperty:MPMediaItemPropertyTitle];
// ...
}
It appears that the following properties are available:
MPMediaItemPropertyMediaType
MPMediaItemPropertyTitle
MPMediaItemPropertyAlbumTitle
MPMediaItemPropertyArtist
MPMediaItemPropertyAlbumArtist
MPMediaItemPropertyGenre
MPMediaItemPropertyComposer
MPMediaItemPropertyPlaybackDuration
MPMediaItemPropertyAlbumTrackNumber
MPMediaItemPropertyAlbumTrackCount
MPMediaItemPropertyDiscNumber
MPMediaItemPropertyDiscCount
MPMediaItemPropertyArtwork
MPMediaItemPropertyLyrics
MPMediaItemPropertyIsCompilation
Doing this without going through the media player framework will be somewhat difficult, and will need an external framework.
ID3 information can be read retrieving the kAudioFilePropertyInfoDictionary
property of an audio file using the AudioFileGetProperty
function of the AudioToolbox framework.
A detailed explanation is available at iphonedevbook.com