我正在尝试从原始文件夹播放音频文件并且它正在播放文件,但我面临的问题是它播放当前文件而下一个文件仅表示一次只有2个文件。我想播放所有文件,直到音乐播放器结束,之后它应该从头开始重复同一个文件。
以下是我正在尝试的代码。
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
playSong(position);
mMediaPlayer.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// check for repeat is ON or OFF
Log.d("---------=========", "inside on completion");
System.out.println("============= inside oncompletiion ====================");
if (isRepeat) {
Log.e("---------------", "Inside on Repeat");
// repeat is on play same song again
playSong(currentSongIndex);
} else if (isShuffle) {
Log.e("---------------", "Inside on Shuffle");
// shuffle is on - play a random song
Random rand = new Random();
currentSongIndex = rand.nextInt((mSongs.length - 1) - 0 + 1) + 0;
playSong(currentSongIndex);
} else {
// no repeat or shuffle ON - play next song
if (currentSongIndex < (mSongs.length - 1)) {
Log.e("---------------", "Next song play");
playSong(currentSongIndex + 1);
currentSongIndex = currentSongIndex + 1;
} else {
// play first song
playSong(0);
currentSongIndex = 0;
}
}
}
});
}
});
对某些代码或方法的建议,通过它继续播放文件。
答案 0 :(得分:0)
我建议的(算法),
将音乐文件的所有资源ID保存在数组(或地图)中,无论您想要哪个
然后保持一个while循环来迭代它。
希望这可以帮助你:)