getCurrentLine method

dynamic getCurrentLine(
  1. int progress
)

Implementation

getCurrentLine(int progress) {
  var lastEndTime = 0;
  for (var i = 0; i < lyrics.length; i++) {
    var element = lyrics[i];
    if (progress >= (element.startTime ?? 0) &&
        progress < (element.endTime ?? 0)) {
      return i;
    }
    lastEndTime = element.endTime ?? 0;
  }
  if (progress > lastEndTime) {
    return lyrics.length - 1;
  } else {
    return 0;
  }
}