streaming .m3u audio

前端 未结 2 1732
眼角桃花
眼角桃花 2020-12-13 16:41

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

This example how i try playing:

final MediaPlayer mp = new MediaPlayer();
           


        
2条回答
  •  独厮守ぢ
    2020-12-13 17:17

    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.

    Use something like this,

    public ArrayList readURLs(String url) {             
            if(url == null) return null;
            ArrayList allURls = new ArrayList();
            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;
            } 
        }
    

提交回复
热议问题