问题描述
任何人可以帮助我如何解析和玩这种.PLS在Android文件
[播放]
NumberOfEntries = 1
文件1 = HTTP://stream.radiosai.net:8002 /
一个快速搜索导致这个非常基本的<$c$c>PlsParser$c$c>从全国公共广播电台的应用程序,通过它的外观,将简单解析.PLS文件并返回所有嵌入的URL字符串列表。你可能会想看一看,作为一个出发点。
在这之后,你应该能够养活网址为的MediaPlayer
的对象,虽然我不能完全肯定是什么格式/协议的支持,或者是限制可能适用于流的情况下。媒体播放器调用的顺序看起来有点像这样。
MediaPlayer的熔点为新的MediaPlayer();
mp.setDataSource(http://stream.radiosai.net:8002/);
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
MP prepare()。 //还要考虑MP。prepareAsync()。
mp.start();
更新:据我所知,你几乎可以从字面上采取引用code,并把它自己使用。请注意,code以下是不完整或测试。
公共类PlsParser {
私人最终的BufferedReader阅读器;
公共PlsParser(字符串URL){
的URLConnection的URLConnection =新的网址(URL).openConnection();
this.reader =新的BufferedReader(新的InputStreamReader(urlConnection.getInputStream()));
}
公开名单&LT;字符串&GT; getUrls(){
链表&LT;字符串&GT;网址=新的LinkedList&LT;字符串&GT;();
而(真){
尝试 {
串线= reader.readLine();
如果(线== NULL){
打破;
}
字符串URL = parseLine(线);
如果(URL = NULL和放大器;!&安培;!url.equals()){
urls.add(URL);
}
}赶上(IOException异常E){
e.printStackTrace();
}
}
返回的网址;
}
私人字符串parseLine(串线){
如果(线== NULL){
返回null;
}
串修整= line.trim();
如果(trimmed.indexOf(HTTP)&GT; = 0){
返回trimmed.substring(trimmed.indexOf(HTTP));
}
返回 ;
}
}
一旦你有,你可以简单地创建一个新的 PlsParser
与.PLS文件的URL,并调用 getUrls
之后。每个列表项将是一个URL作为.PLS文件中找到。你的情况这将只是 http://stream.radiosai.net:8002/
。至于说,你可以再喂这对MediaPlayer的。
can anybody help me how to parse and play this .pls file in android
[playlist]
NumberOfEntries=1
File1=http://stream.radiosai.net:8002/
A quick search resulted in this very basic PlsParser
from the NPR app that, by the looks of it, will simply parse the .pls file and return all embedded URLs in a list of strings. You'll probably want to take a look at that as a starting point.
After that, you should be able to feed the URL to a MediaPlayer
object, although I'm not completely sure about what formats/protocols are supported, or what limitations might apply in the case of streaming. The sequence of media player calls will look somewhat like this.
MediaPlayer mp = new MediaPlayer();
mp.setDataSource("http://stream.radiosai.net:8002/");
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp.prepare(); //also consider mp.prepareAsync().
mp.start();
Update: As far as I can tell, you can almost literally take the referenced code and put it your own use. Note that the code below is by no means complete or tested.
public class PlsParser {
private final BufferedReader reader;
public PlsParser(String url) {
URLConnection urlConnection = new URL(url).openConnection();
this.reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
}
public List<String> getUrls() {
LinkedList<String> urls = new LinkedList<String>();
while (true) {
try {
String line = reader.readLine();
if (line == null) {
break;
}
String url = parseLine(line);
if (url != null && !url.equals("")) {
urls.add(url);
}
} catch (IOException e) {
e.printStackTrace();
}
}
return urls;
}
private String parseLine(String line) {
if (line == null) {
return null;
}
String trimmed = line.trim();
if (trimmed.indexOf("http") >= 0) {
return trimmed.substring(trimmed.indexOf("http"));
}
return "";
}
}
Once you have that, you can simply create a new PlsParser
with the url of the .pls file and call getUrls
afterwards. Each list item will be a url as found in the .pls file. In your case that'll just be http://stream.radiosai.net:8002/
. As said, you can then feed this to the MediaPlayer.
这篇关于解析和Android的播放.PLS文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!