我正在开发一个音频尖叫应用程序,我正在使用Streamingplayer 现在我想要了解当前正在播放的歌曲的信息我该如何获得? 它不作为url的一部分提供,因为它在streamplayer api中显示。 有没有人做过这样的事情然后请回复。
当歌曲改变时,如何更新?
答案 0 :(得分:1)
您可以参考以下链接:http://www.smackfu.com/stuff/programming/shoutcast.html 并可以使用下面的代码
void getMetaData(){
Thread metaDataThread = new Thread(new Runnable(){
public void run(){
try {
metaDataCheckBit = false;
StreamConnection streamConnection=null;
HttpConnection httpConnection = null;
InputStream inputStream =null;
streamConnection=(StreamConnection)Connector.open(newUrl);
httpConnection=(HttpConnection)streamConnection;
httpConnection.setRequestProperty("Icy-metadata", "1");
int httpStatus=httpConnection.getResponseCode();
if(httpStatus==HttpConnection.HTTP_OK){
String mint = httpConnection.getHeaderField("icy-metaint");
inputStream = streamConnection.openInputStream();
int length= Integer.parseInt(mint);
int b = 0;
int count =0;
while(count++ < length){
b = inputStream.read();
}
int metalength = ((int)b)*16;
if(metalength <= 0)return;
byte buf[] = new byte[metalength];
inputStream.read(buf,0,buf.length);
String metaData = new String(buf);
int streamTilleIndex = metaData.indexOf("StreamTitle");
// if(streamTilleIndex <= 0)return;
String streamTille = metaData.substring(streamTilleIndex);
int eqindex = streamTille.indexOf('=');
// if(eqindex <= 0){return;}
int colindex = streamTille.indexOf(';');
// if(colindex <= 0)return;
String metaDatam = streamTille.substring(eqindex, colindex);
int lengthOfMaetaDataM = metaDatam.length();
// if(lengthOfMaetaDataM <= 0){return;}
metaDataParsed =metaDatam.substring(2, lengthOfMaetaDataM-2);
if(metaDataParsed!="")
metaDataCheckBit = true;
}
}
catch (Exception e){
System.out.println(e);
}
}
});
metaDataThread.start();
}