我设法在拖动或触摸搜索栏时更改文字。问题是在单击暂停和播放按钮时更新文本视图。
这是我迄今为止取得的成就,并相应地更新了文本视图
private void primarySeekBarProgressUpdater(){
if(mediaPlayer !=null){
seekBarProgress.setProgress((int) (((float) mediaPlayer.getCurrentPosition() / mediaFileLengthInMilliseconds) * 100)); // This math construction give a percentage of "was playing"/"song length"
totalDuration = mediaPlayer.getDuration();
currentDuration = mediaPlayer.getCurrentPosition();
statusDuration = totalDuration - currentDuration;
}
if(currentDuration > 1000){
btnPause.setVisibility(View.VISIBLE);
//mMaterialProgressBar.setVisibility(View.GONE);
// Displaying Total Duration time
TotalDurationLabel.setText(""+utils.milliSecondsToTimer(statusDuration));
// Displaying time completed playing
CurrentDurationLabel.setText(""+utils.milliSecondsToTimer(currentDuration));
}
if (mediaPlayer.isPlaying() && mediaPlayer !=null) {
notification = new Runnable() {
public void run() {
primarySeekBarProgressUpdater();
}
};
handler.postDelayed(notification, 1000);
}
}
问题在这里。点击放置在framelayout
中的两个按钮的事件btnPause.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isAvailable()) {
// check if we are streaming
if (mediaPlayer.isPlaying() && mediaPlayer != null) {
mediaPlayer.pause();
// Changing button image to play button
btnPause.setImageResource(R.drawable.play_b);
btnPause.setVisibility(View.VISIBLE);
btnPlay.setVisibility(View.GONE);
seekBarProgress.setVisibility(View.VISIBLE);
Log.d(TAG, "Paused but won't update text views");
// }
} else {
// Resume song
if (mediaPlayer != null) {
mediaPlayer.start();
// Changing button image to pause button
btnPause.setImageResource(R.drawable.pause_b);
btnPause.setVisibility(View.VISIBLE);
btnPlay.setVisibility(View.INVISIBLE);
seekBarProgress.setVisibility(View.VISIBLE);
handler.removeCallbacks(notification);
Log.d(TAG, "Check here for playback please");
primarySeekBarProgressUpdater();
}
}
} else {
showMessage("Please enable internet and data to listen music");
}
}
});
我删除了runnable的回调并启动了一个新线程。新主题不会像以前那样更新文本视图