문제

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.

도움이 되었습니까?

해결책

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.

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