我需要使用媒体播放器播放 .M3U 网址,但它不起作用:这是我的代码:
final MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mediaPlayer.setDataSource("http://xxxxxxxxx/1.m3u");
} catch (IOException e) {
e.printStackTrace();
}
try {
mediaPlayer.prepare(); // might take long! (for buffering, etc)
} catch (IOException e) {
e.printStackTrace();
}
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
mediaPlayer.start();
}
});
我已经阅读了关于stackoverflow的所有相关问题,但这对我没有帮助,
我还尝试使用此方法提取 .M3U:
public ArrayList<String> readURLs(String url) {
if (url == null) return null;
ArrayList<String> allURls = new ArrayList<String>();
try {
URL urls = new URL(url);
BufferedReader in = new BufferedReader(new InputStreamReader(urls
.openStream()));
String str;
while ((str = in.readLine()) != null) {
allURls.add(str);
}
Toast.makeText(this, allURls + "", Toast.LENGTH_SHORT).show();
Log.d("URL", String.valueOf(allURls));
in.close();
return allURls;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
但是当我调用它时它也不起作用
readURLs ("http://xxxxxxx.m3u");
所以请帮助我。
提前致谢!