formatVideoTime static method

String formatVideoTime(
  1. int time
)

Implementation

static String formatVideoTime(int time) {
  List<int> times = [];
  if (time <= 0) return '0:01';
  if (time >= TimeConst.DAY_SEC) return '1d+';
  for (int idx = 0; idx < TimeConst.SEC_SERIES.length; idx++) {
    int sec = TimeConst.SEC_SERIES[idx];
    if (time >= sec) {
      times.add((time / sec).floor());
      time = time % sec;
    } else if (idx > 0) {
      times.add(0);
    }
  }
  times.add(time);
  String formatTime = times[0].toString();
  for (int idx = 1; idx < times.length; idx++) {
    if (times[idx] < 10) {
      formatTime += ':0${times[idx].toString()}';
    } else {
      formatTime += ':${times[idx].toString()}';
    }
  }
  return formatTime;
}