Search code examples
androidhttp-live-streamingandroid-mediaplayer

Android http live Streaming URL using mediaplayer


I am trying to play an url but its not playing and the code i used is below..the logcat is showing Mediaplayer error(1,-1002), start state is 0 and error(-38, 0) why...? where i am going wrong......can u help me out how to play........

       import java.io.IOException;

       import android.app.Activity;
       import android.media.AudioManager;
       import android.media.MediaPlayer;
         import android.os.Bundle;
      import android.view.View;
      import android.widget.ImageButton;
       import android.widget.TextView;

        public class BacaFatihahActivity extends Activity {



        final String songs_urIs= "http://stream.radiosai.net:8002/";
           // private TextView txt_song_title;
        private MediaPlayer mediaplayer;
        @Override
         public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  ImageButton btn_play = (ImageButton) findViewById(R.id.button_play);
  ImageButton btn_pause = (ImageButton) findViewById(R.id.button_pause);
  ImageButton btn_next = (ImageButton) findViewById(R.id.button_next);
  ImageButton btn_previous = (ImageButton) findViewById(R.id.button_Previous);
  //txt_song_title = (TextView) findViewById(R.id.txt_song_title);

  mediaplayer = new MediaPlayer();
  mediaplayer.setAudioStreamType(AudioManager.STREAM_MUSIC);


  btn_play.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
        try {
            mediaplayer.setDataSource(songs_urIs);
        } 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 {
            mediaplayer.prepare();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
         mediaplayer.start();   
    }
       });


        }
       }

Solution

  • right code but wrong api level~

    it's not every api level supports this way to play a media,http live streaming ,may be you need api level 10 or higher