简体   繁体   English

Android MediaPlayer音频流-使用哪个URL?

[英]Android MediaPlayer audio streaming - which URL to use?

I'm learning android programming and have been trying the MediaPlayer with audio streaming. 我正在学习android编程,并且一直在尝试带音频流的MediaPlayer。 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. Android指南很清楚,您只需要指定URL,但是我很想确定该URL实际是什么,我应该在代码中包括以流式传输各种广播电台。 (I'm not trying to play an mp3 file somewhere on the internet, but actually use "true" streaming). (我并不是试图在Internet上的某个地方播放mp3文件,而是实际上使用了“真”流)。
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? 我在下面描述的是到目前为止我发现的内容,并且可以正常运行,但是这看起来似乎很模糊,我的问题是:是否有更好的方法来确定要使用的URL?
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. 其次,我看了shoutcast,并尝试选择它使用的URL。 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. 对于我看过的广播电台(例如www.rockradio1.com),它正在启动.pls文件(根据Wikipedia的播放列表文件),VLC对此文件进行了解释并开始播放流式音乐。 However, giving the .pls file to my android program didn't work. 但是,将.pls文件提供给我的android程序无效。 I then looked inside the .pls file to find something like: 然后,我在.pls文件中查找了以下内容:

[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. 当我将其中一个网址提供给Android程序时,它工作正常。 Also looking around the rockradio1 site I came across a playlist file with 我还环顾了rockradio1网站,发现了一个播放列表文件,其中包含

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. 但是,要获得这些URL似乎有点困难,而且我猜测适当的流客户端可能会以更复杂的方式进行操作。 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. 我个人只是将其用作学习练习,而不是尝试开发任何商业软件,但是我会对如何更好地确定要使用的URL感兴趣。

Could you write a wrapper function which downloads the .pls file from the URL you define, and then extracts the URLs from it? 您能否编写一个包装函数,从您定义的URL下载.pls文件,然后从中提取URL? 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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM