所以我几乎已经完成了我的项目,我需要最后一点帮助,使用随机播放按钮。
@Override
public void onCompletion(MediaPlayer mp1) {
try {
if(isRepeat == true) {
mp.start();
}
else if(isShuffle == true) {
mp.reset();
Random rand = new Random();
SONG_NUMBER = rand.nextInt((songs.size() - 1) - 0 + 1) + 0;
mp.setDataSource(SD_PATH + songs.get(SONG_NUMBER));
mp.start();
}
else
{
mp.reset();
SONG_NUMBER += 1;
mp.setDataSource(SD_PATH + songs.get(SONG_NUMBER));
mp.prepare();
mp.start();
}
play.setEnabled(false);
pause.setEnabled(true);
stop.setEnabled(true);
next.setEnabled(true);
prev.setEnabled(true);
replay.setEnabled(true);
shuffle.setEnabled(true);
}
catch(IOException e) {
Log.v(getString(R.string.app_name), e.getMessage());
}
}
单击随机播放按钮时,会将isShuffle
设置为true
,但当歌曲结束时,音乐播放器会完全停止。有人能帮忙吗?
logcat的:
10-27 12:00:51.858: W/SignalStrength(724): getGsmLevel ro.show.3g.level.by.rscp = false
10-27 12:00:51.859: W/SignalStrength(566): getGsmLevel ro.show.3g.level.by.rscp = false
10-27 12:00:51.859: W/SignalStrength(671): getGsmLevel ro.show.3g.level.by.rscp = false
10-27 12:00:51.861: W/SignalStrength(671): getGsmLevel ro.show.3g.level.by.rscp = false
10-27 12:00:51.863: E/ActivityManager(566): Intent: Intent { act=android.intent.action.SIG_STR flg=0x10 (has extras) }mEnablePowerSaverManagerFunction:truesuperMode:false
10-27 12:00:56.979: W/SignalStrength(724): getGsmLevel ro.show.3g.level.by.rscp = false
10-27 12:00:56.980: W/SignalStrength(566): getGsmLevel ro.show.3g.level.by.rscp = false
10-27 12:00:56.981: W/SignalStrength(671): getGsmLevel ro.show.3g.level.by.rscp = false
10-27 12:00:56.983: W/SignalStrength(671): getGsmLevel ro.show.3g.level.by.rscp = false
10-27 12:00:56.988: E/ActivityManager(566): Intent: Intent { act=android.intent.action.SIG_STR flg=0x10 (has extras) }mEnablePowerSaverManagerFunction:truesuperMode:false
10-27 12:00:57.434: E/ActivityManager(566): Intent: Intent { act=android.intent.action.BATTERY_CHANGED flg=0x60000010 (has extras) }mEnablePowerSaverManagerFunction:truesuperMode:false
10-27 12:01:00.008: E/ActivityManager(566): Intent: Intent { act=android.intent.action.TIME_TICK flg=0x40000014 (has extras) }mEnablePowerSaverManagerFunction:truesuperMode:false
10-27 12:01:02.101: W/SignalStrength(724): getGsmLevel ro.show.3g.level.by.rscp = false
10-27 12:01:02.102: W/SignalStrength(566): getGsmLevel ro.show.3g.level.by.rscp = false
10-27 12:01:02.103: W/SignalStrength(671): getGsmLevel ro.show.3g.level.by.rscp = false
10-27 12:01:02.105: W/SignalStrength(671): getGsmLevel ro.show.3g.level.by.rscp = false
10-27 12:01:02.110: E/ActivityManager(566): Intent: Intent { act=android.intent.action.SIG_STR flg=0x10 (has extras) }mEnablePowerSaverManagerFunction:truesuperMode:false
答案 0 :(得分:1)
mp.reset();
Random rand = new Random();
SONG_NUMBER = rand.nextInt((songs.size() - 1) - 0 + 1) + 0;
mp.setDataSource(SD_PATH + songs.get(SONG_NUMBER));
mp.prepare(); // Try this line
mp.start();
我认为这是随机播放模式和普通模式之间的唯一区别