When I play a file repeatedly, various errors occur, such as isPlaying stop and different errors are reported. The following is my code. Please help me! Thanks!
public void playerVoice(String json) {
if (TextUtils.isEmpty(json))
return;
JSONObject jsonObject = JSON.parseObject(json);
if (player == null) {
player = new MediaPlayer();
player.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
player.start();
}
});
player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.stop();
mp.reset();
}
});
}
try {
if (player.isPlaying()) {
player.stop();
player.reset();
}
} catch (Exception e) {
player.stop();
player.reset();
}
try {
player.setDataSource(jsonObject.getString("fullPath"));
player.prepareAsync();
} catch (IOException e) {
e.printStackTrace();
}
}
player.reset(); Try removing this code and try it