Added functions to convert milliseconds into a more readable String
This commit is contained in:
parent
baca017e2a
commit
f2a54f8505
|
@ -117,7 +117,7 @@ public class MediaplayerActivity extends SherlockActivity {
|
||||||
protected void onProgressUpdate(Long... values) {
|
protected void onProgressUpdate(Long... values) {
|
||||||
super.onProgressUpdate(values);
|
super.onProgressUpdate(values);
|
||||||
txtvPosition.setText(
|
txtvPosition.setText(
|
||||||
Integer.toString(playbackService.getPlayer().getCurrentPosition()));
|
Converter.getDurationStringLong(playbackService.getPlayer().getCurrentPosition()));
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -136,8 +136,8 @@ public class MediaplayerActivity extends SherlockActivity {
|
||||||
imgvCover.setImageBitmap(
|
imgvCover.setImageBitmap(
|
||||||
media.getItem().getFeed().getImage().getImageBitmap());
|
media.getItem().getFeed().getImage().getImageBitmap());
|
||||||
|
|
||||||
txtvPosition.setText(Integer.toString(player.getCurrentPosition()));
|
txtvPosition.setText(Converter.getDurationStringLong((player.getCurrentPosition())));
|
||||||
txtvLength.setText(Integer.toString(player.getDuration()));
|
txtvLength.setText(Converter.getDurationStringLong(player.getDuration()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,11 @@ public final class Converter {
|
||||||
/** Determines the length of the number for best readability.*/
|
/** Determines the length of the number for best readability.*/
|
||||||
private static final int NUM_LENGTH = 1000;
|
private static final int NUM_LENGTH = 1000;
|
||||||
|
|
||||||
|
|
||||||
|
private static final int HOURS_MIL = 3600000;
|
||||||
|
private static final int MINUTES_MIL = 60000;
|
||||||
|
private static final int SECONDS_MIL = 1000;
|
||||||
|
|
||||||
/** Takes a byte-value and converts it into a more readable
|
/** Takes a byte-value and converts it into a more readable
|
||||||
* String.
|
* String.
|
||||||
* @param input The value to convert
|
* @param input The value to convert
|
||||||
|
@ -53,4 +58,24 @@ public final class Converter {
|
||||||
return "ERROR";
|
return "ERROR";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Converts milliseconds to a string containing hours, minutes and seconds */
|
||||||
|
public static String getDurationStringLong(int duration) {
|
||||||
|
int h = duration / HOURS_MIL;
|
||||||
|
int rest = duration - h * HOURS_MIL;
|
||||||
|
int m = rest / MINUTES_MIL;
|
||||||
|
rest -= m * MINUTES_MIL;
|
||||||
|
int s = rest / SECONDS_MIL;
|
||||||
|
|
||||||
|
return String.format("%02d:%02d:%02d", h, m, s);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Converts milliseconds to a string containing hours and minutes */
|
||||||
|
public static String getDurationStringShort(int duration) {
|
||||||
|
int h = duration / HOURS_MIL;
|
||||||
|
int rest = duration - h * HOURS_MIL;
|
||||||
|
int m = rest / MINUTES_MIL;
|
||||||
|
|
||||||
|
return String.format("%02d:%02d", h, m);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue