3
    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?

halfer
  • 19,824
  • 17
  • 99
  • 186
David Zorychta
  • 13,039
  • 6
  • 45
  • 81
  • http://stackoverflow.com/questions/8681550/android-2-2-mediaplayer-is-working-fine-with-one-shoutcast-url-but-not-with-the http://stackoverflow.com/questions/8671479/android-mediaplayer-works-fine-in-our-custom-audio-streaming-application-up-to-a – Yaqub Ahmad Feb 11 '12 at 05:23
  • @Yaqub The problem persists after having looked at that already and as I mentioned in my question I am using 4.0.3, not a varient of 2.X. – David Zorychta Feb 11 '12 at 20:57
  • I am having exactly the same problem.. I tried almost everything to solve it with no success. Have you found any solution to it? – polerto Apr 26 '12 at 20:56

4 Answers4

3

I was having the same issue so I decided simply to try it on a real device (4.0.4). It worked. Seems like an emulator issue to me.

Binary Boy
  • 31
  • 2
1
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();
}
itsmewajid
  • 186
  • 2
  • 9
0

I suggest you

  1. test with other URL
  2. try removing third line
Marko
  • 20,385
  • 13
  • 48
  • 64
The_ehT
  • 1,202
  • 17
  • 32
-1

I'm using this code for a shout cast stream works okay. Just need to add a controller using a surfaceview in XML.

private String shoutcastsource = "Your http:\\223.example.80.4003"

 surfaceView = (SurfaceView)findViewById(R.id.surface);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);

surfaceView.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if(mediaController != null){
            mediaController.show();
        }
        return false;
    }
});

}

@Override
public void surfaceCreated(SurfaceHolder holder) {

Toast.makeText(radiostation.this,
        "Media Controls active lets mash it up", Toast.LENGTH_LONG).show();
mediaPlayer = new MediaPlayer();
mediaPlayer.setDisplay(surfaceHolder);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setOnPreparedListener(this);
try {
    mediaPlayer.setDataSource(shoutcastsource);
    mediaPlayer.prepare();

    mediaController = new MediaController(this);

} catch (IOException e) {
    e.printStackTrace();
    Toast.makeText(radiostation.this,
            "Radio Station off Air or no internet connection!\n" + e.toString(),
            Toast.LENGTH_LONG).show();
}
}

@Override
public void surfaceChanged(SurfaceHolder holder,
                       int format, int width, int height) {

}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {

}

@Override
public void onPrepared(MediaPlayer mp) {
mediaPlayer.start();
Toast.makeText(radiostation.this,
        "You are now connected to Ukn-Radio the home of the mash up", Toast.LENGTH_LONG).show();

mediaController.setMediaPlayer(this);
mediaController.setAnchorView(surfaceView);
handler.post(new Runnable() {

    public void run() {
        mediaController.setEnabled(true);
        mediaController.show();
    }
});
}

@Override
public void start() {
mediaPlayer.start();
}

@Override
public void pause() {
mediaPlayer.pause();
}

@Override
public int getDuration() {
return mediaPlayer.getDuration();
}

@Override
public int getCurrentPosition() {
return mediaPlayer.getCurrentPosition();
}

@Override
public void seekTo(int pos) {
mediaPlayer.seekTo(pos);
}

@Override
public boolean isPlaying() {
return mediaPlayer.isPlaying();
}

@Override
public int getBufferPercentage() {
return 0;
}

@Override
  public boolean canPause() {
return true;
}

  @Override
public boolean canSeekBackward() {
return false;
}

@Override
public boolean canSeekForward() {
return false;
}

@Override
public int getAudioSessionId() {
return mediaPlayer.getAudioSessionId();
}
@Override
public void onBackPressed() {

mediaPlayer.stop();
mediaPlayer.release();
mediaPlayer=null;
finish();
}

}

Edit

Also make sure you allow internet access in your Android manifest:

  <uses-permission android:name="android.permission.INTERNET" />
halfer
  • 19,824
  • 17
  • 99
  • 186
markharrop
  • 866
  • 1
  • 9
  • 30