0

I'm learning android programming and have been trying the MediaPlayer with audio streaming. The Android guide is clear that you just have to specify the URL, but I got rather stuck with working out what that URL should actually be that I should include in the code to stream various radio stations. (I'm not trying to play an mp3 file somewhere on the internet, but actually use "true" streaming).
What I've described below is what I've uncovered so far, and I've got it to work ok, but it all seems rather kludgy and my question is: is there a better way to determine which URLs to use?
First of all I came across an excellent article on Basics of streaming protocols. Secondly, I looked at shoutcast, and try to pick on the URLs it was using. For the radio stations I looked at (eg www.rockradio1.com) it was launching a .pls file (playlist file according to wikipedia) which VLC interpreted and starting playing the streamed music. However, giving the .pls file to my android program didn't work. I then looked inside the .pls file to find something like:

[playlist]
numberofentries=5
File1=http://91.121.7.49:8000
Title1=(#1 - 177/400) RockRadio1.Com - Classic Hard Rock and Heavy Metal Mix, 24/7 Live Requests / www.rockradio1.com
Length1=-1
File2=http://91.121.195.222:8000
Title2=(#2 - 186/400) RockRadio1.Com - Classic Hard Rock and Heavy Metal Mix, 24/7 Live Requests / www.rockradio1.com
Length2=-1
File3=http://91.121.75.155:8000
Title3=(#3 - 190/400) RockRadio1.Com - Classic Hard Rock and Heavy Metal Mix, 24/7 Live Requests / www.rockradio1.com
Length3=-1
File4=http://77.74.192.50:8000
Title4=(#4 - 70/100) RockRadio1.Com - Classic Hard Rock and Heavy Metal Mix, 24/7 Live Requests / www.rockradio1.com
Length4=-1
File5=http://176.31.235.147:8000
Title5=(#5 - 351/500) RockRadio1.Com - Classic Hard Rock and Heavy Metal Mix, 24/7 Live Requests / www.rockradio1.com
Length5=-1
Version=2

When I gave one of those URLs to the Android program it worked ok. Also looking around the rockradio1 site I came across a playlist file with

File1=http://rockradio1-3.mixstream.net 

and plugging that URL worked ok too. However, it all seems a bit of a hack to get at these URLs, and I'm guessing that there might be a more sophisticated way that proper streaming clients operate. Personally I'm just use this as a learning exercise and not trying to develop any commercial software, but I would be interested of how I should better go about determining the URLs to use.

Robbie Jackson
  • 268
  • 2
  • 6

1 Answers1

0

Could you write a wrapper function which downloads the .pls file from the URL you define, and then extracts the URLs from it? This SO question seems to address doing just that. There's a bit of code embedded in the answer there that probably does what you want.

Community
  • 1
  • 1
LeoR
  • 369
  • 1
  • 9
  • So what you're suggesting is to use something like the shoutcast URLs of the form http://yp.shoutcast.com/sbin/tunein-station.pls?id=558051 to get the PLS file, then parse it and feed the URLs from it to the Android MediaPlayer. Yes, that sounds a good approach. Thanks for the link; I'll give that a go. I presume the ids are fairly static. – Robbie Jackson Jan 16 '14 at 22:53
  • Pretty much. As long as you're basing your streaming URL selection off what's current right now on the shoutcast site (or wherever you're pulling the data from) then you shouldn't run into any issues. Hardcoding URLs which aren't public facing (and so are likely to change) could be an issue. What IDs do you mean? You could expand the parser methods given in the linked SO question to also extract titles and other metadata. It's really just a question of moving through the file line by line and reading the first characters to see what the line represents. – LeoR Jan 17 '14 at 09:20
  • With regard to ids, I mean that as you look at the shoutcast web site all the radio stations have a URL of the form http://yp.shoutcast.com/sbin/tunein-station.pls?id=558051 where the id is different for each radio station. (The tooltip they present is different - you have to Copy Link Location to get the actual URL). It would be nice to present the song titles as they change, but as that must be in the streaming protocol either the MediaPlayer would have to show that (if I presented it in a View) or there might be something passed in MediaPlayer.OnInfoListener. More investigation needed! – Robbie Jackson Jan 17 '14 at 10:21