Android: Redirecting pls file so that mediaplayer can read it

青春壹個敷衍的年華 提交于 2019-12-31 06:20:02

问题


I want to play a radio shoutcast but its a pls file format by looking at the link: http://yp.shoutcast.com/sbin/tunein-station.pls?id=13361 It doesn't play at the moment,

I have got:

Initializing:

 player = new MediaPlayer();


        try {
            player.setDataSource("http://yp.shoutcast.com/sbin/tunein-station.pls?id=13361");
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SecurityException 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();
        }

When play button is pressed:

player.setOnPreparedListener(new OnPreparedListener() {

        public void onPrepared(MediaPlayer mp) {

        player.start();

        }
    });

I have the code tested with another shoutcast link that ends with a port like www.example.com:8080 or something like that, it was working pretty fine, but when the link changed to a pls?id= it doesn't read the link and hence I can't hear the radio... Someone please help me with this :-/


回答1:


A .pls file is just a playlist. There is no media there. You will have the parse the file yourself to get the actual stream URLs. Open it up in a text editor to see what I mean.



来源:https://stackoverflow.com/questions/14027728/android-redirecting-pls-file-so-that-mediaplayer-can-read-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!