Skip to content

Instantly share code, notes, and snippets.

@codingwithsara
Created November 27, 2018 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codingwithsara/a0400a0e7138a034985990a78c511d32 to your computer and use it in GitHub Desktop.
Save codingwithsara/a0400a0e7138a034985990a78c511d32 to your computer and use it in GitHub Desktop.
Android MusicPlayer 5
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
int currentPosition = msg.what;
// 再生位置を更新
positionBar.setProgress(currentPosition);
// 経過時間ラベル更新
String elapsedTime = createTimeLabel(currentPosition);
elapsedTimeLabel.setText(elapsedTime);
// 残り時間ラベル更新
String remainingTime = createTimeLabel(totalTime-currentPosition);
remainingTimeLabel.setText("- " + remainingTime);
}
};
public String createTimeLabel(int time) {
String timeLabel = "";
int min = time / 1000 / 60;
int sec = time / 1000 % 60;
timeLabel = min + ":";
if (sec < 10) timeLabel += "0";
timeLabel += sec;
return timeLabel;
}
public void playBtnClick(View view) {
if (!mp.isPlaying()) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment