本文介绍了如何使用Media Player Android随机播放列表歌曲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在Mediaplayer中完成了歌曲列表的随机播放,但是确实无法解决问题,请帮忙:
I've done shuffle in mediaplayer for a list of songs but dos not correct work please help:
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
if (isShuffle) {
if (intent.hasExtra("songIndex")) {
Random random = new Random();
songIndex = random.nextInt((songList.size() - 1) + 1);
playSongWithIndex(songIndex);
}
}
}
播放歌曲的方法:
public void playSongWithIndex(final int songIndex) {
progressBar.setVisibility(View.VISIBLE);
if (music_exist.exists()) {
playMusicOfflineMode();
} else {
Log.e("TAG", "playSongWithIndex: "+songList.get(songIndex).getFile_128() );
try {
G.mediaPlayer.reset();
G.mediaPlayer.setDataSource(songList.get(songIndex).getFile_128());
G.mediaPlayer.prepareAsync();
G.mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
runOnUiThread(new Runnable() {
@Override
public void run() {
setAdapterLyric(songManager.showTextInRecyclerView(songList.get(songIndex).getLyric()));
}
});
G.mediaPlayer.start();
music_name_text.setText(songList.get(songIndex).getEn_name());
singer_name_text.setText(songList.get(songIndex).getSinger_name_en());
comment_count_text.setText(songList.get(songIndex).getComment_count() + "");
like_count_text.setText(songList.get(songIndex).getLike_count() + "");
play_music_img.setImageResource(R.drawable.ic_pause_black_24dp);
seekBar.setMax(G.mediaPlayer.getDuration());
progressBar.setVisibility(View.INVISIBLE);
play_music_img.setEnabled(true);
timer = new Timer();
timer.schedule(new MainTimer(), 0, 1000);
}
});
} catch (IllegalArgumentException | IllegalStateException | IOException e) {
e.printStackTrace();
}
}
}
我遇到了这个日志:
E/TAG: playSongWithIndex: http://cdn.oneremind.com/up/song/Modern_Talking/Let's_Talk_About_Love/04_Let's_Talk_About_Love.mp3
E/TAG: playSongWithIndex: http://cdn.oneremind.com/up/song/Modern_Talking/Let's_Talk_About_Love/03_Don't_Give_Up.mp3
E/TAG: playSongWithIndex: http://cdn.oneremind.com/up/song/Modern_Talking/Let's_Talk_About_Love/04_Let's_Talk_About_Love.mp3
E/TAG: playSongWithIndex: http://cdn.oneremind.com/up/song/Modern_Talking/Let's_Talk_About_Love/03_Don't_Give_Up.mp3
E/TAG: playSongWithIndex: http://cdn.oneremind.com/up/song/Modern_Talking/Let's_Talk_About_Love/04_Let's_Talk_About_Love.mp3
E/TAG: playSongWithIndex: http://cdn.oneremind.com/up/song/Modern_Talking/Let's_Talk_About_Love/01_Cheri_Cheril_Lady.mp3
E/TAG: playSongWithIndex: http://cdn.oneremind.com/up/song/Modern_Talking/Let's_Talk_About_Love/01_Cheri_Cheril_Lady.mp3
E/TAG: playSongWithIndex: http://cdn.oneremind.com/up/song/Modern_Talking/Let's_Talk_About_Love/02_With_A_Little_Love.mp3
E/TAG: playSongWithIndex: http://cdn.oneremind.com/up/song/Modern_Talking/Let's_Talk_About_Love/03_Don't_Give_Up.mp3
E/TAG: playSongWithIndex: http://cdn.oneremind.com/up/song/Modern_Talking/Let's_Talk_About_Love/02_With_A_Little_Love.mp3
E/TAG: playSongWithIndex: http://cdn.oneremind.com/up/song/Modern_Talking/Let's_Talk_About_Love/03_Don't_Give_Up.mp3
E/TAG: playSongWithIndex: http://cdn.oneremind.com/up/song/Modern_Talking/Let's_Talk_About_Love/02_With_A_Little_Love.mp3
E/TAG: playSongWithIndex: http://cdn.oneremind.com/up/song/Modern_Talking/Let's_Talk_About_Love/02_With_A_Little_Love.mp3
E/TAG: playSongWithIndex: http://cdn.oneremind.com/up/song/Modern_Talking/Let's_Talk_About_Love/02_With_A_Little_Love.mp3
E/TAG: playSongWithIndex: http://cdn.oneremind.com/up/song/Modern_Talking/Let's_Talk_About_Love/03_Don't_Give_Up.mp3
E/TAG: playSongWithIndex: http://cdn.oneremind.com/up/song/Modern_Talking/Let's_Talk_About_Love/03_Don't_Give_Up.mp3
E/TAG: playSongWithIndex: http://cdn.oneremind.com/up/song/Modern_Talking/Let's_Talk_About_Love/01_Cheri_Cheril_Lady.mp3
E/TAG: playSongWithIndex: http://cdn.oneremind.com/up/song/Modern_Talking/Let's_Talk_About_Love/01_Cheri_Cheril_Lady.mp3
E/TAG: playSongWithIndex: http://cdn.oneremind.com/up/song/Modern_Talking/Let's_Talk_About_Love/04_Let's_Talk_About_Love.mp3
E/TAG: playSongWithIndex: http://cdn.oneremind.com/up/song/Modern_Talking/Let's_Talk_About_Love/01_Cheri_Cheril_Lady.mp3
E/TAG: playSongWithIndex: http://cdn.oneremind.com/up/song/Modern_Talking/Let's_Talk_About_Love/04_Let's_Talk_About_Love.mp3
E/TAG: playSongWithIndex: http://cdn.oneremind.com/up/song/Modern_Talking/Let's_Talk_About_Love/01_Cheri_Cheril_Lady.mp3
E/TAG: playSongWithIndex: http://cdn.oneremind.com/up/song/Modern_Talking/Let's_Talk_About_Love/02_With_A_Little_Love.mp3
E/TAG: playSongWithIndex: http://cdn.oneremind.com/up/song/Modern_Talking/Let's_Talk_About_Love/03_Don't_Give_Up.mp3
E/TAG: playSongWithIndex: http://cdn.oneremind.com/up/song/Modern_Talking/Let's_Talk_About_Love/01_Cheri_Cheril_Lady.mp3
E/TAG: playSongWithIndex: http://cdn.oneremind.com/up/song/Modern_Talking/Let's_Talk_About_Love/02_With_A_Little_Love.mp3
E/TAG: playSongWithIndex: http://cdn.oneremind.com/up/song/Modern_Talking/Let's_Talk_About_Love/01_Cheri_Cheril_Lady.mp3
E/TAG: playSongWithIndex: http://cdn.oneremind.com/up/song/Modern_Talking/Let's_Talk_About_Love/02_With_A_Little_Love.mp3
E/TAG: playSongWithIndex: http://cdn.oneremind.com/up/song/Modern_Talking/Let's_Talk_About_Love/03_Don't_Give_Up.mp3
E/TAG: playSongWithIndex: http://cdn.oneremind.com/up/song/Modern_Talking/Let's_Talk_About_Love/04_Let's_Talk_About_Love.mp3
并且Media Player卡在一个循环中,不起作用,我的问题出在哪里?
and Media Player is stuck in a loop ,dos not work where is my problem?
推荐答案
为什么不通过这种方式创建媒体播放器?
Why not create Media player with this way?
G.mediaPlayer = MediaPlayer.create(this,Uri.parse("YourFilePath");//this is a context
//Then start it without preparation.
G.mediaPlayer.start();
这篇关于如何使用Media Player Android随机播放列表歌曲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!