seek method

  1. @override
Future<void> seek(
  1. Duration duration, {
  2. bool synchronized = true,
})
override

Seeks the currently playing Media in the Player by specified Duration.

Implementation

@override
Future<void> seek(Duration duration, {bool synchronized = true}) {
  Future<void> function() async {
    if (disposed) {
      throw AssertionError('[Player] has been disposed');
    }

    await waitForPlayerInitialization;
    await waitForVideoControllerInitializationIfAttached;

    await compute(
      _seek,
      _SeekData(
        ctx.address,
        NativeLibrary.path,
        duration,
      ),
    );

    // It is self explanatory that PlayerState.completed & PlayerStream.completed must enter the false state if seek is called. Typically after EOF.
    // https://github.com/media-kit/media-kit/issues/221
    state = state.copyWith(completed: false);
    if (!completedController.isClosed) {
      completedController.add(false);
    }
  }

  if (synchronized) {
    return lock.synchronized(function);
  } else {
    return function();
  }
}