Question

I have a stream from an icecast server downloading, and I can grab the information in the headers by doing the following:

 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); pos++; }

When I do this all of the headers I receive are shown as:

content-type : audio/mpeg icy-br : 64 ice-audio-info : ice-samplerate=22050;ice-bitrate=64;ice-channels=2 icy-br : 64 icy-description : RadioStation icy-genre : Classical, New Age, Ambient icy-name : RadioStation Example icy-private : 0 icy-pub : 1 icy-url : http://exampleradio.com server : Icecast 2.3.2 cache-control : no-cache

However if I open my stream in mplayer I get:

 ICY Info: StreamTitle='artist - album - trackname' 

and with each time the song is changed, the new track information is sent appearing the same way in mplayer.

In android when I attempt to read the icy-info all I get returned is null. Also how would I go about retrieving the new information from the headers while I am buffering from the stream? Because even if I try to read the header of something I already know exists whilst buffering such as:

  Log.e(getClass().getName()," "+cn.getHeaderField("icy-br"));

All I get returned is null.

I hope this makes sense, I can post more code on request.

Was it helpful?

Solution

I realize this question is old, but for others who are facing this challenge, I am using this project: http://code.google.com/p/streamscraper/ to get track information from an icecast stream. I'm using it on android and so far it works as expected.

OTHER TIPS

All you need is to setDataSource() and pass the URL as a String, then you must prepareAsync() and with a mp.setOnPreparedListener(this); or etc. you will get noticed when the MediaPlayer is done buffering, then all you need to do is mp.start(); P.S.: Don't forget to mp.stop, mp.reset and mp.release upon destroying the application. ;) I'm still thinking of a way to read the ICY info... I must either make my own buffering mechanism and write a buffer file (init the MediaPlayer with FileDescriptor) or make a separate connection from time to time to check for ICY info tags and close the connection... Any better ideas anyone?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top