lyricTimeToDuration static method

Duration lyricTimeToDuration(
  1. String time
)

Implementation

static Duration lyricTimeToDuration(String time) {
  int minuteSeparatorIndex = time.indexOf(":");
  int secondSeparatorIndex = time.indexOf(".");

  // 分
  var minute = time.substring(0, minuteSeparatorIndex);
  // 秒
  var seconds =
      time.substring(minuteSeparatorIndex + 1, secondSeparatorIndex);
  // 微秒
  var millsceconds = time.substring(secondSeparatorIndex + 1);
  var microseconds = '0';
  // 判断是否存在微秒
  if (millsceconds.length > 3) {
    // 存在微秒 重新给予赋值
    microseconds = millsceconds.substring(3);
    millsceconds = millsceconds.substring(0, 3);
  }

  return Duration(
      minutes: int.parse(minute),
      seconds: int.parse(seconds),
      milliseconds: int.parse(millsceconds),
      microseconds: int.parse(microseconds));
}