Reading MP3 information using objective c
Asked Answered
C

3

11

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.

Cargill answered 6/8, 2009 at 14:56 Comment(3)
When you say you have mp3 files stored on the phone, do you mean your application has mp3 files somewhere in its sandbox (either in your bundle or that you downloaded), or do you mean the user has loaded them via iTunes? Querying the media player for information about songs on the device is a completely different problem than parsing information out files.Burk
This was answered already in this SO question: https://mcmap.net/q/1014154/-how-to-extract-id-tags-from-mp3-files-in-cocoaCirculation
Hi Louis, The mp3 files are files downloaded from web and stored in documents folder of my application. Thanks for pointing out confusion. TonyCargill
A
19

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.

Armageddon answered 13/8, 2009 at 0:22 Comment(3)
Provided link asks for permissions :(Severin
Page is no longer available. I've replaced with a similar, but less complete link.Armageddon
This StackOverflow answer is clear and gives source code.Foscalina
D
5

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.

Dramamine answered 11/8, 2009 at 23:6 Comment(1)
He cannot use e Media Player because the files are MP3s in his apps documents folder, not music that is part of the the system wide music collection.Burk
B
3

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 library 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.

Burk answered 11/8, 2009 at 8:51 Comment(4)
id3.org had an overview of available libraries. But it seems they are currently down. You can try the google cached version: 209.85.135.132/search?q=cache:khgjN7xyYeoJ:www.id3.org/…Circulation
When linking an LGPL library the entire source of your application should be released to adhere to the terms of the LGPL license.Armageddon
LGPLv2.1 does not require source code to be released, it requires intermediate objects " If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights."Burk
Interesting; I was unaware of that.Armageddon

© 2022 - 2024 — McMap. All rights reserved.