我想让mediaplayer
播放下一首歌,并让seekbar不断前进。但是,现在seekbar在播放下一首歌时重置回0。
我怎样才能让seekBar在播放下一首歌时不重置回0?
下面是我的onCompletion
方法:
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
mp.release();
if(currentTrack < tracks.length) {
currentTrack++;
if (currentTrack >= 2) {
currentTrack = 0;
}
mp = MediaPlayer.create(this, tracks[currentTrack]);
mp.setOnCompletionListener(this);
if (currentTrack > 0) {
mp.seekTo(tracks[currentTrack]);
}
handler.post(UpdateSongTime);
mp.start();
}
}
下面是更新所有定位的线程:
private Runnable UpdateSongTime = new Runnable() {
@Override
public void run() {
if(mp.isPlaying()) {
startTime = mp.getCurrentPosition() / 1000;
seekBar.setMax(songEndTime);
int currentSongEndTime = songEndTime - mp.getCurrentPosition()/1000;
startTimeText.setText(convertSeekLength(startTime));
String endTime = "-" + convertSeekLength(currentSongEndTime);
songDisplay.setText(songArrayList.get(currentTrack).getTitle());
endTimeText.setText(endTime);
seekBar.setProgress(startTime);
handler.postDelayed(this, 100);
}
}
};
2条答案
按热度按时间eiee3dmh1#
我自己刚刚创建了一个解决方案,涉及创建一个
Arraylist of mediaPlayers
,而不仅仅是制作one mediaPlayer
。下面是工作代码,如果有人需要它:
和螺纹:
ugmeyewa2#
当播放下一首歌曲时,时间组
seekBar.setProgress(0);