Android 如何从在线流媒体电台获取流媒体网址
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21158164/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get streaming url from online streaming radio station
提问by Ahmad Dwaik 'Warlock'
I've been asked to make unofficial online streaming android application for a certain radio station.
I've experience with streaming in android for certain mp3 or whatever stream.
But I don't know the stream urlto provide in mediaPlayer.setDataSource(url).
我被要求为某个广播电台制作非官方的在线流 android 应用程序。
我有在 android 中流式传输某些 mp3 或任何流的经验。
但我不知道stream url在mediaPlayer.setDataSource(url).
Is there any way to get the stream url from the ofiicial streaming page for ex. this radio stream?
有什么方法可以从官方流媒体页面获取流网址,例如。这个广播流?
回答by Shahar
not that hard,
没那么难,
if you take a look at the page source, you'll see that it uses to stream the audio via shoutcast.
如果您查看页面源,您会看到它用于通过shoutcast 流式传输音频。
this is the stream url
这是流网址
which returns a JSON like that:
它返回一个像这样的 JSON:
{
"Streams": [
{
"StreamId": 3244651,
"Reliability": 92,
"Bandwidth": 64,
"HasPlaylist": false,
"MediaType": "MP3",
"Url": "http://mp3hdfm32.hala.jo:8132",
"Type": "Live"
}
]
}
i believe that's the url you need: http://mp3hdfm32.hala.jo:8132
我相信这是你需要的网址:http: //mp3hdfm32.hala.jo: 8132
回答by Json
Edited ZygD's answer for python 3.x.:
编辑了 ZygD 对 python 3.x. 的回答:
import re
import urllib.request
import string
url1 = input("Please enter a URL from Tunein Radio: ");
request = urllib.request.Request(url1);
response = urllib.request.urlopen(request);
raw_file = response.read().decode('utf-8');
API_key = re.findall(r"StreamUrl\":\"(.*?),\"",raw_file);
#print API_key;
#print "The API key is: " + API_key[0];
request2 = urllib.request.Request(str(API_key[0]));
response2 = urllib.request.urlopen(request2);
key_content = response2.read().decode('utf-8');
raw_stream_url = re.findall(r"Url\": \"(.*?)\"",key_content);
bandwidth = re.findall(r"Bandwidth\":(.*?),", key_content);
reliability = re.findall(r"lity\":(.*?),", key_content);
isPlaylist = re.findall(r"HasPlaylist\":(.*?),",key_content);
codec = re.findall(r"MediaType\": \"(.*?)\",", key_content);
tipe = re.findall(r"Type\": \"(.*?)\"", key_content);
total = 0
for element in raw_stream_url:
total = total + 1
i = 0
print ("I found " + str(total) + " streams.");
for element in raw_stream_url:
print ("Stream #" + str(i + 1));
print ("Stream stats:");
print ("Bandwidth: " + str(bandwidth[i]) + " kilobytes per second.");
print ("Reliability: " + str(reliability[i]) + "%");
print ("HasPlaylist: " + str(isPlaylist[i]));
print ("Stream codec: " + str(codec[i]));
print ("This audio stream is " + tipe[i].lower());
print ("Pure streaming URL: " + str(raw_stream_url[i]));
i = i + 1
input("Press enter to close")
回答by ColorCodin
Shahar's answer was really helpful, but I found it quite tedious to do this all myself, so I made a nifty little Python program:
Shahar 的回答真的很有帮助,但我发现自己做这一切很乏味,所以我做了一个漂亮的小 Python 程序:
import re
import urllib2
import string
url1 = raw_input("Please enter a URL from Tunein Radio: ");
open_file = urllib2.urlopen(url1);
raw_file = open_file.read();
API_key = re.findall(r"StreamUrl\":\"(.*?),",raw_file);
#print API_key;
#print "The API key is: " + API_key[0];
use_key = urllib2.urlopen(str(API_key[0]));
key_content = use_key.read();
raw_stream_url = re.findall(r"Url\": \"(.*?)\"",key_content);
bandwidth = re.findall(r"Bandwidth\":(.*?),", key_content);
reliability = re.findall(r"lity\":(.*?),", key_content);
isPlaylist = re.findall(r"HasPlaylist\":(.*?),",key_content);
codec = re.findall(r"MediaType\": \"(.*?)\",", key_content);
tipe = re.findall(r"Type\": \"(.*?)\"", key_content);
total = 0
for element in raw_stream_url:
total = total + 1
i = 0
print "I found " + str(total) + " streams.";
for element in raw_stream_url:
print "Stream #" + str(i + 1);
print "Stream stats:";
print "Bandwidth: " + str(bandwidth[i]) + " kilobytes per second."
print "Reliability: " + str(reliability[i]) + "%"
print "HasPlaylist: " + str(isPlaylist[i]) + "."
print "Stream codec: " + str(codec[i]) + "."
print "This audio stream is " + tipe[i].lower() + "."
print "Pure streaming URL: " + str(raw_stream_url[i]) + ".";
i = i + 1
raw_input("Press enter to close TMUS.")
It's basically Shahar's solution automated.
它基本上是自动化的 Shahar 解决方案。
回答by eagle00789
When you go to a stream url, you get offered a file. feed this file to a parser to extract the contents out of it. the file is (usually) plain text and contains the url to play.
当您转到流 url 时,您会得到一个文件。将此文件提供给解析器以从中提取内容。该文件(通常)是纯文本并包含要播放的网址。
回答by SPRBRN
The provided answers didn't work for me. I'm adding another answer because this is where I ended up when searching for radio stream urls.
提供的答案对我不起作用。我正在添加另一个答案,因为这是我在搜索无线电流网址时结束的地方。
Radio Browser is a searchable site with streaming urls for radio stations around the world:
Radio Browser 是一个可搜索的站点,其中包含世界各地广播电台的流媒体 URL:
http://www.radio-browser.info/
http://www.radio-browser.info/
Search for a station like FIP, Pinguin Radioor Radio Paradise, then click the save button, which downloads a PLS file that you can open in your radioplayer (Rhythmbox), or you open the file in a text editor and copy the URL to add in Goodvibes.
搜索FIP、Pinguin Radio或Radio Paradise 之类的电台,然后单击保存按钮,这会下载您可以在广播播放器 (Rhythmbox) 中打开的 PLS 文件,或者您在文本编辑器中打开该文件并复制 URL 以添加在好感。

