currentSheenChapter function Music

int currentSheenChapter(
  1. List<SheenChapter> chapters,
  2. Duration position
)

The index of the chapter that holds position in chapters (sorted by start), or -1 when there are none or position is before the first.

Implementation

int currentSheenChapter(List<SheenChapter> chapters, Duration position) {
  var at = -1;
  for (var i = 0; i < chapters.length; i++) {
    if (chapters[i].start <= position) at = i;
  }
  return at;
}