Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading MP3 information using objective c

I have mp3 files stored on the iPhone and I my application should to be able to read the ID3 information, i.e length in seconds, artist, etc. Does anyone know how to do this or what library to use in Objective-C?

Your thoughts are much appreciated.

like image 743
TonyNeallon Avatar asked Aug 06 '09 14:08

TonyNeallon


2 Answers

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

edit: Original link is now down. InformIT has some similar sample code, but it's not as complete.

like image 149
rpetrich Avatar answered Oct 20 '22 00:10

rpetrich


Look into the Media Player framework:

  • Guide
  • Reference
  • All documentation

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.

like image 44
John Calsbeek Avatar answered Oct 20 '22 01:10

John Calsbeek