0
String url = "http://23.101.29.94:1111/text1.mp3";
    MediaPlayer mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    try {
        mediaPlayer.setDataSource(url);
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        mediaPlayer.prepare();
    } catch (IOException e) {
        e.printStackTrace();
    }
    mediaPlayer.start();

When it run:

2019-11-04 20:55:31.221 13816-13816/com.example.loginlogout E/MediaPlayerNative: start called in state 0, mPlayer(0xe9a85440)
2019-11-04 20:55:31.221 13816-13816/com.example.loginlogout E/MediaPlayerNative: error (-38, 0)
2019-11-04 20:55:31.235 13816-13816/com.example.loginlogout E/MediaPlayer: Error (-38,0)

but this url (http://23.101.29.94:1111/text1.mp3) run well in browser, How I fix that

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Trí Phan
  • 11
  • 3

1 Answers1

1

You need to call mediaPlayer.start() in the onPrepared method by using a listener. Listeners can be attached simply by

mediaPlayer.setOnPreparedListener(new OnPreparedListener() {
    @Override
    public void onPrepared(MediaPlayer mp) {
        mediaPlayer.start();
    }
});
KOD Dev
  • 11
  • 2