使用AudioStreamer获取MP3 ID3元数据和歌曲持续时间 [英] Get MP3 ID3 meta data and song duration using AudioStreamer

查看:58
本文介绍了使用AudioStreamer获取MP3 ID3元数据和歌曲持续时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用马特·加拉格尔的AudioStreamer 通过HTTP播放MP3.我需要知道歌曲的持续时间和ID3标签.

I'm using Matt Gallagher's AudioStreamer to play MP3s over HTTP. I need to know the duration of the song and the ID3 tags.

是否可以在AudioStreamer中实现此功能?如何实现?

Is it possible to implement this in the AudioStreamer, and how?

推荐答案

来自他的文档:

有限范围

一点应该是 在我继续之前进行了澄清: 类用于流音频. 通过流媒体,我不仅仅意味着 通过HTTP传输的音频文件". 相反,我的意思是连续的HTTP 源无止境,持续不断 无限期地(例如广播电台, 不是一首歌.

Limited scope

One point should be clarified before I continue: this class is intended for streaming audio. By streaming, I don't simply mean "an audio file transferred over HTTP". Instead, I mean a continuous HTTP source without an end that continues indefinitely (like a radio station, not a single song).

这似乎意味着获得持续时间可能很困难.

This seems to imply that getting the duration might be tough.

以下是获取ID3v2标签的方法:

Here is how to get the ID3v2 tags:

获取元数据

最简单的来源 元数据来自HTTP标头. 在 - 的里面 handleReadFromStream:eventType: 方法,使用CFReadStreamCopyProperty 复制 kCFStreamPropertyHTTPResponseHeader CFReadStreamRef中的属性, 那么你可以使用 CFHTTPMessageCopyAllHeaderFields到 将标头字段复制到 回复.对于许多流音频 服务器,流名称是以下之一 这些字段.

Get metadata

The easiest source of metadata comes from the HTTP headers. Inside the handleReadFromStream:eventType: method, use CFReadStreamCopyProperty to copy the kCFStreamPropertyHTTPResponseHeader property from the CFReadStreamRef, then you can use CFHTTPMessageCopyAllHeaderFields to copy the header fields out of the response. For many streaming audio servers, the stream name is one of these fields.

相对困难的来源 元数据是ID3标签. ID3v1是 始终在文件末尾(因此 流媒体时无用). ID3v2是 位于一开始,所以可能会更多 可访问的.

The considerably harder source of metadata are the ID3 tags. ID3v1 is always at the end of the file (so is useless when streaming). ID3v2 is located at the start so may be more accessible.

我从没看过ID3标签,但我 怀疑如果您缓存第一个 文件的几百千字节 在加载的某个地方,打开该缓存 与AudioFileOpenWithCallbacks和 然后读取kAudioFilePropertyID3Tag 有了AudioFileGetProperty,您可能会 能够读取ID3数据(如果有) 存在).就像我说的:我已经 从来没有真正做到过,所以我不 肯定知道它会起作用.

I've never read the ID3 tags but I suspect that if you cache the first few hundred kilobytes of the file somewhere as it loads, open that cache with AudioFileOpenWithCallbacks and then read the kAudioFilePropertyID3Tag with AudioFileGetProperty you may be able to read the ID3 data (if it exists). Like I said though: I've never actually done this so I don't know for certain that it would work.

这篇关于使用AudioStreamer获取MP3 ID3元数据和歌曲持续时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆