Display Metadata from icecast server in Android Ap

2019-09-16 19:16发布

问题:

I want to get the metadata information from one of icecast streaming servers and display such data in my Android Application. Any recommendation?

using the below code , I am not able to get the full metadata ( artist and the title ....)

code

String  stringUrl="http://dev.kigen.co:8000/xrm-ele.opus";

URL url = null;
try {
    url = new URL(stringUrl);
} catch (MalformedURLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
URLConnection cn = null;
try {
    cn = url.openConnection();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}   
try {
    cn.connect();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}   

int pos=1;
String x;
String y;

while (cn.getHeaderField(pos) != null) { 
    x=cn.getHeaderFieldKey(pos); 
    y = cn.getHeaderField(x); 
    System.out.println(":::::"+""+x+" : "+y); 
    pos++; 
}

}

generated output

:::::Server : Steamcast Distributed Network Media Server/1.0.0 decennium (Windows 64-bit)
:::::Date : Sat, 24 Oct 2015 16:52:16 GMT
:::::Connection : Keep-Alive
:::::Content-Type : application/ogg
:::::Cache-Control : max-age=0, no-cache, no-store
:::::Expires : Mon, 25 Jan 2002 10:11:57 GMT
:::::Pragma : no-cache
:::::ice-name : [XRM] - Electronic
:::::ice-genre : Electronic, Dance, Trance
:::::ice-url : http://www.xrm.fm/
:::::ice-public : 1
:::::ice-bitrate : 64
:::::ice-description : XRM Electronic in OGG Opus
:::::ice-audio-info : 
:::::Transfer-Encoding : chunked
:::::Set-Cookie : __steam_sess=8134e975470ac65a-5edd5a42-4a1b-6f58-87d4e64dc919bc08fb1821b0; path=/

回答1:

I see your using my Steamcast server. This is not Icecast and as such is a bit different. However, the biggest problem is you are using an Opus stream. These are OGG encapsulated streams. You could try using android.media.MediaMetadataRetriever to retrieve the metadata. Different version of Android have different capabilities. So it might not work correctly on all versions.