使用objective c读取MP3信息

发布于 2024-07-29 20:45:44 字数 148 浏览 6 评论 0原文

我在 iPhone 上存储了 mp3 文件,我的应用程序应该能够读取 ID3 信息,即长度(以秒为单位)、艺术家等。 有谁知道如何做到这一点或在 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

千秋岁 2024-08-05 20:45:45

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

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

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.

ぃ弥猫深巷。 2024-08-05 20:45:44

可以使用 AudioToolbox 框架的 AudioFileGetProperty 函数来读取 ID3 信息,检索音频文件的 kAudioFilePropertyInfoDictionary 属性。

详细说明可在 iphonedevbook.com

编辑:原始链接现在已经下降了。 InformIT 有一些类似的示例代码,但它并不像完全的。

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.

身边 2024-08-05 20:45:44

查看媒体播放器框架:

这要求相关 MP3 是手机上 iPod 库的一部分。

例如,确定手机上每个媒体文件的名称(包括电影、播客等):

MPMediaQuery *everything = [[MPMediaQuery alloc] init];

NSArray *itemsFromGenericQuery = [everything items];
for (MPMediaItem *item in itemsFromGenericQuery) {
    NSString *itemTitle = [item valueForProperty:MPMediaItemPropertyTitle];
    // ...
}

似乎可以使用以下属性:

  • MPMediaItemPropertyMediaType
  • MPMediaItemPropertyTitle
  • MPMediaItemPropertyAlbumTitle
  • MPMediaItemPropertyArtist
  • MPMediaItemPropertyAlbumArtist
  • MPMediaItemPropertyGenre
  • MPMediaItemPropertyComposer
  • MPMediaItemPropertyPlaybackDuration
  • MPMediaItemPropertyAlbumTrackNumber
  • MPMediaItemPropertyAlbumTrackCount
  • MPMediaItemPropertyDiscNumber
  • MPMediaItemPropertyDiscCount MPMediaItemPropertyArtwork
  • MPMediaItemPropertyLyrics
  • MPMediaItemPropertyIsCompilation code>

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文