我有一个从 icecast 服务器下载的流,我可以通过执行以下操作来获取 header 中的信息:
URLConnection cn = new URL(mediaUrl).openConnection();
cn.connect();
int pos=1;
String x;
String y;
while (cn.getHeaderField(pos) != null) { x=cn.getHeaderFieldKey(pos); y = cn.getHeaderField(x); Log.e("::::::",""+x+": "+y); 位置++;
当我这样做时,我收到的所有 header 都显示为:
内容类型:音频/mpeg 冰镇 : 64 ice-audio-info : ice-samplerate=22050;ice-bitrate=64;ice-channels=2 冰镇 : 64 冰冷的描述:RadioStation 冰冷风格:古典,新时代,环境 icy-name : RadioStation 示例 冰冷的私有(private):0 冰酒吧:1 冰冷的网址:http://exampleradio.com 服务器:Icecast 2.3.2 缓存控制:无缓存
但是,如果我在 mplayer 中打开流,我会得到:
ICY Info: StreamTitle='artist - album - trackname'
每次更改歌曲时,新的轨道信息都会以相同的方式发送到 mplayer 中。
在 android 中,当我尝试读取 icy-info 时,我返回的所有内容都是空的。另外,当我从流中缓冲时,我将如何从标题中检索新信息?因为即使我在缓冲时尝试读取我已经知道存在的内容的标题,例如:
Log.e(getClass().getName()," "+cn.getHeaderField("icy-br"));
我得到的返回都是空的。
我希望这是有道理的,我可以根据要求发布更多代码。
最佳答案
我意识到这个问题很老了,但是对于面临这个挑战的其他人,我正在使用这个项目:http://code.google.com/p/streamscraper/从 icecast 流中获取轨道信息。我在 android 上使用它,到目前为止它按预期工作。
关于Android从icecast服务器流式传输获取轨道信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2730754/