javaandroidstreammediashoutcast

Why won't this Java Android SHOUTcast MediaPlayer app code work?


    String url = "http://91.121.140.11:8000/";
    MediaPlayer mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setDataSource(url);
    mediaPlayer.prepare();
    mediaPlayer.start();

I am using Android 4.0.3 to test this and have tried it on a physical device and the emulator. The app opens but I cannot hear anything. I thought they added support for SHOUTcast streams. Have I done something wrong?


Solution

  • MediaPlayer mp;
    @Override
    public void onCreate(){
    mp = new MediaPlayer();
    mp.setOnPreparedListener(this);
    }
    public void prepareplayer(){
    mp.setDataSource(Url);
    mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
    Log.d(TAG, "Preparing..");
    mp.prepareAsync();
    }
    
    @Override
    public void onPrepared(MediaPlayer mp) {
    // TODO Auto-generated method stub
    Log.d(TAG, "Prepared");
    mp.play();
    }