문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top