如何获取 iPhone 中音频文件的详细信息
我使用 AVAudioPlayer 制作了自定义播放器。现在,我想获取添加在资源文件夹中的音频文件的详细信息,例如艺术家姓名、专辑名称等。
MPMusicPlayer 提供了用于获取详细信息的 API,但它使用 iPod 库并且不从应用程序的沙箱中获取资源。因此,MPMusicPlayer 在这种情况下不起作用。
那么,我们如何获取iPhone中音频文件的详细信息呢?
I made the custom player by using AVAudioPlayer. Now, I want to fetch the details of the audio file such as artist name,album name,etc which is added in the resource folder.
MPMusicPlayer provides the API for fetching the details but its using iPod library and its not taking the resource from sandbox of application. So, MPMusicPlayer is not going to work in that scenario.
So, how can we fetch the details of audio file in iPhone.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过
AudioToolbox.framework
获取此信息。AudioToolbox.framework
是一个 C API,所以我为它编写了一个 Objective-C 包装器:ID3Tag .h:
ID3TagParser.h
ID3TagParser.m
You can get this information through the
AudioToolbox.framework
. TheAudioToolbox.framework
is a C API, so I wrote an Objective-C wrapper for it:ID3Tag .h:
ID3TagParser.h
ID3TagParser.m
我看到标签读取代码 韦恩帖子被复制粘贴得太多了。
如果您使用
kAudioFilePropertyInfoDictionary
,则不需要id3DataSize,不需要读取原始ID3Tag数据,并且也不会使用id3TagSizeLength id3TagSize。只需打开文件并读取标签即可:字典键在 AudioFile.h 中定义,以 kAFInfoDictionary 开头。
然而,还有另一个标签读取键,它会返回不同的结果(与其他键):
I see that the tag-reading code Wayne posts is being copy-pasted too much.
If you use
kAudioFilePropertyInfoDictionary
, you don't need id3DataSize, don't need to read raw ID3Tag data and id3TagSizeLength id3TagSize are not used also. Just open the file and read the tag:Dicionary keys are defined in AudioFile.h, starting with kAFInfoDictionary.
However, there is another tag-reading key, which will return different results (with other keys):