问题
Background: I'm streaming radio using double buffering approach for html shoutcast. I get metadata information from stream using http://www.smackfu.com/stuff/programming/shoutcast.html
Problem
I have three problems.
1- I already use a urlconnection and inputstream for listening radio. I don't want to open a new connection to retrieve metadata. But when I tried to get both from same inputstream, I couldn't listen radio anymore. I guess this is not possible and I have to use two seperate connection? Isn't it bad for performance?
2- When the application started, I retrieve the info of the current song. No problem. However how do I get informed when the song changes. It is said that server will send information when the song changes. But I'm starting the URLconnection, get the input stream, retrieve the metadata and close the connection. I couldn't understand how should I informed by the server? Should I keep the connection open?
3- And last question. AFAIK progressive streaming isn't possible before android 2.2. Is this true just for http? If the protocol was rtsp, could I make progressive streaming before android 2.2? Anyone please make it certain and clear?
Thanks a lot,
回答1:
You must remember number from icy-metaint header field.
After receiving that many bytes from stream (which you send to audio decoder), you must expect metadata part, and read this (also not sending these data to audio decoder). Then you again receive encoded audio from stream, and continue the process of periodically reading metadata after icy-metaint bytes.
This means that server sends metadata (info about artist / song title) periodically, and your code must split the input stream to audio and metadata.
回答2:
- You're not supposed to open new connection for metadata. Metadata is integrated into MP3 stream (all this is described in the link you posted).
- If you close the connection obviously you're no longer be able to receive MP3 stream nor metadata.
- See: Streaming Audio from A URL in Android using MediaPlayer?
来源:https://stackoverflow.com/questions/7593361/how-to-get-informed-of-new-song-info-while-retrieving-metadata-from-shoutcast-st