xcode 使用目标 c 读取 MP3 信息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1239460/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:43:08  来源:igfitidea点击:

Reading MP3 information using objective c

iphoneobjective-cxcodemetadatampnowplayinginfocenter

提问by TonyNeallon

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

我有mp3文件存储在 iPhone 上,我的应用程序应该能够读取ID3信息,即以秒为单位的长度、艺术家等。有谁知道如何做到这一点或在 Objective-C 中使用什么库?

Your thoughts are much appreciated.

非常感谢您的想法。

回答by rpetrich

ID3 information can be read retrieving the kAudioFilePropertyInfoDictionaryproperty of an audio file using the AudioFileGetPropertyfunction of the AudioToolbox framework.

可以kAudioFilePropertyInfoDictionary使用AudioFileGetPropertyAudioToolbox 框架的功能读取 ID3 信息以检索音频文件的属性。

A detailed explanation is available at iphonedevbook.com

详细说明可在iphonedevbook.com 上找到

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

编辑:原始链接现已关闭。InformIT有一些类似的示例代码,但并不完整。

回答by John Calsbeek

Look into the Media Player framework:

查看媒体播放器框架:

This requires that the MP3 in question is part of the iPod library on the phone.

这要求有问题的 MP3 是手机上 iPod 库的一部分。

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

在不通过媒体播放器框架的情况下执行此操作会有些困难,并且需要外部框架。

回答by Louis Gerbarg

There are not many ID3 parsing libraries out there that are not GPLed. There is on Objective-C frameworkthat 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.

没有多少非 GPL 的 ID3 解析库。有一个 Objective-C框架可能可以修改为静态链接时在 iPhone 上工作,但它是 LGPL。为了使用静态链接的二进制文件满足 LGPL 的条款,您必须提供足够的中间组件,以便有人可以将其与自己的库版本重新链接,这对于 iPhone 应用程序来说是困难的(但并非不可能)。当然,由于我没有处于必须这样做的位置,因此我实际上并没有与律师讨论过这个问题,而且由于我不是律师,因此您不应将其视为权威。

Your best bet if you don't feel like consulting a lawyer is to use a more liberally licensed C library like libID3and 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.

如果您不想咨询律师,最好的选择是使用更自由的 C 库,例如libID3,并将其包装在某些 Objective C 类中。我还建议直接包含代码,而不是处理所有静态库构建和链接问题,但这只是个人风格。