【发布时间】:2016-09-05 10:51:20
【问题描述】:
我正在尝试从原始文件夹播放音频文件,它正在播放文件,但我面临的问题是它播放当前文件,下一个文件一次只意味着 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;
}
}
}
});
}
});
对一些代码或方法的任何建议,通过它一个接一个地继续播放文件。
【问题讨论】:
-
您可能应该寻找诸如此类的音乐播放器教程,并学习播放文件的一些重要方面,例如随机播放、播放暂停等:code.tutsplus.com/tutorials/…
标签: android audio audio-player android-music-player