move method

  1. @override
Future<void> move(
  1. int from,
  2. int to, {
  3. bool synchronized = true,
})
override

Moves the playlist Media at from, so that it takes the place of the Media to.

Implementation

@override
Future<void> move(int from, int to, {bool synchronized = true}) {
  Future<void> function() async {
    if (disposed) {
      throw AssertionError('[Player] has been disposed');
    }
    await waitForPlayerInitialization;
    await waitForVideoControllerInitializationIfAttached;

    // External List<Media>:
    // ---------------------------------------------
    final map = SplayTreeMap<double, Media>.from(
      current.asMap().map((key, value) => MapEntry(key * 1.0, value)),
    );
    final item = map.remove(from * 1.0);
    if (item != null) {
      map[to - 0.5] = item;
    }
    final values = map.values.toList();
    current = values;
    // ---------------------------------------------

    final command = 'playlist-move $from $to'.toNativeUtf8();
    mpv.mpv_command_string(
      ctx,
      command.cast(),
    );
    calloc.free(command.cast());
  }

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