我被要求为某个广播电台制作非官方的在线流媒体安卓应用程序。
我有过在某些 mp3 或任何流的安卓流媒体中的经验。
但我不知道在mediaPlayer.setDataSource(url)
中提供stream url
.
有没有办法从官方流媒体页面获取流 url,例如这个无线电流?
没那么难,
如果您查看页面源代码,您会发现它用于通过 shoutcast 流式传输音频。
这是流网址
"流网址": "http://stream.radiotime.com/listen.stream?streamIds=3244651&rti=c051HQVbfRc4FEMbKg5RRVMzRU9KUBw%2fVBZHS0dPF1VIExNzJz0CGQtRcX8OS0o0CUkYRFJDDW8LEVRxGAEOEAcQXko%2bGgwSBBZrV1pQZgQZZxkWCA4L%7e%7e%7e",
它返回如下的 JSON:
{
"Streams": [
{
"StreamId": 3244651,
"Reliability": 92,
"Bandwidth": 64,
"HasPlaylist": false,
"MediaType": "MP3",
"Url": "http://mp3hdfm32.hala.jo:8132",
"Type": "Live"
}
]
}
我相信这就是您需要的网址:http://mp3hdfm32.hala.jo:8132
这是车站网站
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")
提供的答案对我不起作用。我正在添加另一个答案,因为这是我在搜索无线电流 url 时最终到达的地方。
广播浏览器是一个可搜索的网站,其中包含世界各地广播电台的流媒体网址:
http://www.radio-browser.info/
搜索像FIP,Pinguin Radio或Radio Paradise这样的电台,然后单击保存按钮,这将下载一个PLS文件,您可以在收音机播放器(Rhythmbox)中打开该文件,或者在文本编辑器中打开该文件并复制URL以添加到Goodvibes中。
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.")
这基本上是Shahar的解决方案自动化。
当您转到流 URL 时,系统会为您提供一个文件。 将此文件提供给解析器以从中提取内容。 该文件(通常)是纯文本,包含要播放的 URL。