MediaPlayer.setDataSource() and prepare() not working - android
Try MediaPlayer.create(), you also may want to start only after player is actually ready, for example:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MediaPlayer player = MediaPlayer.create(this, Uri.parse("http://www.urltofile.com/file.mp3"));
player.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.start();
}
});
}
For streams, you should call prepareAsync()
, which returns immediately, rather than blocking until enough data has been buffered.