流m3u格式的音频音频、格式、m3u

2023-09-04 08:05:14 作者:哥脫了,你随意

我想打流媒体广播(m3u格式格式),但我不知道该怎么做。

I want play streaming radio( .m3u format ), but i do not know how do it.

这例子我如何努力打:

final MediaPlayer mp = new MediaPlayer();
        try {
            mp.setDataSource("url.m3u");
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {
            mp.prepare();
            mp.start();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

这code不起作用。 请帮助。

this code does not work. help please.

推荐答案

您必须先下载M3U文件。这只是一个文本文件,一行行读它。每一行都会有,你可以在你的媒体播放器读取的链接。

You have to download the M3U file first. It's just a text file, read it line by line. Each line will have a link which you can read in your media player.

使用这样的事情,

public ArrayList<String> readURLs(String url) {             
        if(url == null) return false;
        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);
            }
            in.close();
            return allURls ;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        } 
    }