I have a problem to reproduce more than one mp3 file using MediaPlayer in Android. I\'m able to reproduce one single file but I did not find nothing useful to reproduce diff
May be the simplest solution is to implement setOnCompletionListener. Whenever your audio is completely played , this lifecycle is called and you can load and play next audio, so when the next audio is finished this lifecycle is called again, and on and on.
player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
AssetFileDescriptor afd = null;
if (fileCounter == playlist.size() - 1) {
//for reloading playlist
fileCounter = 0;
}
if (fileCounter < playlist.size() - 1) {
try {
afd = getContext().getAssets().openFd("Audios/" + playlist.get(++fileCounter).getName() + ".mp3");
player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
player.prepare();
player.start();
} catch (IOException e) {
e.printStackTrace();
}
}
}
});