6

I am developing an Application that needs to play Radio from Shout cast. For API I have followed this URL

I am successful in getting a station ID with my developer ID.Now in the section " How To Tune Into A Station " they have guided how to tune to a particular station. I have followed that section and used this URL in my android media player. But my media player plays nothing.

Please note my target SDK is 16 and Min SDK is 13. So I hope android version is not a problem. Media player works fine if am using other URLs like:

So I guess there is no issue with my media player. I have already gone through the post that are available in SO. Please help.

public class MainActivity extends Activity {

        Button play,pause,stop;
        private MediaPlayer mediaPlayer;
        private String out;
//      private String url = "http://yp.shoutcast.com/sbin/tunein-station.pls?id=175821";
//      private String url = "http://www.hrupin.com/wp-content/uploads/mp3/testsong_20_sec.mp3";

        private String url1 = "http://streamplus8.leonex.de:14910";
        private String url2 ="http://s2.voscast.com:7016/";
        private String url3 ="http://s8.voscast.com:7024/";
        private String url4 ="http://s8.voscast.com:7020/";
        private String url5 ="http://s5.voscast.com:8216/";

        private boolean pauseState = false;
        ProgressDialog pd;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);

                pd = new ProgressDialog(this);
                pd.setMessage("Loading your song....");
                play = (Button)findViewById(R.id.btn_play);
                pause = (Button)findViewById(R.id.btn_pause);
                stop = (Button)findViewById(R.id.btn_stop);

                mediaPlayer = new MediaPlayer();
                this.setVolumeControlStream(AudioManager.STREAM_MUSIC);  
            try {
                mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                mediaPlayer.setDataSource(url2);
                mediaPlayer.prepareAsync();
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(), "Please check your connection!", Toast.LENGTH_LONG).show();
                e.printStackTrace();
            }

            play.setOnClickListener(new OnClickListener() {                    
                        @Override
                        public void onClick(View arg0) {

                                if(pauseState == true) {
                    mediaPlayer.start();
                } else {
                        pd.show();
                    mediaPlayer.setOnPreparedListener(new OnPreparedListener() {
                        @Override
                        public void onPrepared(MediaPlayer mp) {
                            mediaPlayer.start();
                            if(mediaPlayer.isPlaying()){
                                pd.dismiss();
                            }
                        }
                    });
                }
                                pauseState = false;                            
                        }
                });
            pause.setOnClickListener(new OnClickListener() {                   
                        @Override
                        public void onClick(View arg0) {
                                mediaPlayer.pause();
                                pauseState = true;                             
                        }
                });
            stop.setOnClickListener(new OnClickListener() {                    
                        @Override
                        public void onClick(View arg0) {
                                mediaPlayer.stop();
//                              mediaPlayer.release();
                        }
                });


        }

}
Ahmed Ekri
  • 4,601
  • 3
  • 23
  • 42
Syamantak Basu
  • 905
  • 4
  • 10
  • 20

2 Answers2

4

Ok. fine I finally figured out myself. Actually when I hit this Url one .pls file is getting downloaded. The content of .pls file is something like this

[playlist]
numberofentries=1
File1=http://203.150.225.71:8000
Title1=(#1 - 10866/10000) COOLfahrenheit 93
Length1=-1
Version=2

I have to read this file and then parse this file to get the actual URL.Here it is

http://203.150.225.71:8000

Android media player is able to play this URL.

Syamantak Basu
  • 905
  • 4
  • 10
  • 20
1

I don't want to download .pls file so that i find other solution. Finally, i got simple shoutcast streaming app. Try this. Just change streaming url in StreamService.java.

B M
  • 1,863
  • 1
  • 25
  • 40
  • You have used the same url inside file there too :O – A_rmas Mar 30 '16 at 09:01
  • What do you mean? In StreamService.java, you just change your url to String url = "http://176.31.115.196:8214/"; you need to set url to mediaplayer datasource. That sample project will run with your stream url. – B M Mar 31 '16 at 02:46
  • _176.31.115.196:8214_ Isn't this the url we get after downloading the file and read from it? – A_rmas Mar 31 '16 at 03:30
  • 1
    no. my solution is not read the file. Just play shoutcast server public url. you need to know your shoutcast steam server public url. – B M Mar 31 '16 at 07:02
  • hello @BM, I have two stream url at server so it is not working , but i tried with ur url then it is working.. please help me!! – curiousMind May 17 '17 at 10:59
  • @BM how to get the shoutcast stream server public url? – Harry .Naeem Aug 19 '18 at 20:11
  • @Harry.Naeem I got public url from streaming server hosting. – B M Aug 20 '18 at 02:08