seek method

Future<void> seek(
  1. Duration? position, {
  2. int? index,
})

Seeks to a particular position. If a composition of multiple AudioSources has been loaded, you may also specify index to seek to a particular item within that sequence. This method has no effect unless an audio source has been loaded.

A null position seeks to the head of a live stream.

Implementation

Future<void> seek(final Duration? position, {int? index}) async {
  if (_disposed) return;
  _initialSeekValues = null;
  switch (processingState) {
    case ProcessingState.loading:
      return;
    default:
      try {
        _seeking = true;
        final prevPlaybackEvent = _playbackEvent;
        _playbackEvent = prevPlaybackEvent.copyWith(
          updatePosition: position,
          updateTime: DateTime.now(),
        );
        _playbackEventSubject.add(_playbackEvent);
        _positionDiscontinuitySubject.add(PositionDiscontinuity(
            PositionDiscontinuityReason.seek,
            prevPlaybackEvent,
            _playbackEvent));
        await (await _platform)
            .seek(SeekRequest(position: position, index: index));
      } finally {
        _seeking = false;
      }
  }
}