2

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,

efeyc
  • 2,122
  • 2
  • 27
  • 39

2 Answers2

3
  1. 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).
  2. If you close the connection obviously you're no longer be able to receive MP3 stream nor metadata.
  3. See: Streaming Audio from A URL in Android using MediaPlayer?
Community
  • 1
  • 1
pingw33n
  • 12,292
  • 2
  • 37
  • 38
  • But for Shoutcast streams, it seems that metadata cannot be retrieved using `MediaPlayer`, so another connection is needed to read the stream and extract this metadata. – jul Jun 29 '13 at 12:58
2

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.

Pointer Null
  • 39,597
  • 13
  • 90
  • 111
  • Finally i got the point. Now i get both live stream and metadata, however i have another problem. While i'm transferring the buffered data to the player, there occurs small gaps about a few seconds. – efeyc Sep 30 '11 at 06:44
  • Strange. Slow connection? Make sure to buffer enough data for decoder to always have some 2 seconds of audio. If there's less, better stop playback and pre-buffer more with message displayed to user. – Pointer Null Sep 30 '11 at 07:00