VideoController constructor

VideoController(
  1. Player player, {
  2. VideoControllerConfiguration configuration = const VideoControllerConfiguration(),
})

PlatformVideoController

This class provides the interface for platform specific VideoController implementations. The platform specific implementations are expected to implement the methods accordingly.

The subclasses are then used in composition with the VideoController class, based on the platform the application is running on.

Implementation

VideoController(
  Player player, {
  VideoControllerConfiguration configuration =
      const VideoControllerConfiguration(),
}) {
  player.platform?.isVideoControllerAttached = true;

  () async {
    try {
      if (WebVideoController.supported) {
        // TODO(@alexmercerind): Missing implementation.
      } else if (NativeVideoController.supported) {
        final result = await NativeVideoController.create(
          player,
          configuration,
        );
        platform.complete(result);
        notifier.value = result;
      } else if (AndroidVideoController.supported) {
        final result = await AndroidVideoController.create(
          player,
          configuration,
        );
        platform.complete(result);
        notifier.value = result;
      }
    } catch (exception, stacktrace) {
      debugPrint(exception.toString());
      debugPrint(stacktrace.toString());
    }
    if (platform.isCompleted) {
      // Populate [id] & [rect] [ValueNotifier]s with the values from [platform] implementation of [PlatformVideoController].
      final controller = await platform.future;
      // Add listeners.
      void fn0() => id.value = controller.id.value;
      void fn1() => rect.value = controller.rect.value;
      fn0();
      fn1();
      controller.id.addListener(fn0);
      controller.rect.addListener(fn1);
      // Remove listeners upon [Player.dispose].
      player.platform?.release.add(() async {
        controller.id.removeListener(fn0);
        controller.rect.removeListener(fn1);
      });
    } else {
      platform.completeError(
        UnimplementedError(
          '[VideoController] is unavailable for this platform.',
        ),
      );
    }

    if (!(player.platform?.videoControllerCompleter.isCompleted ?? true)) {
      player.platform?.videoControllerCompleter.complete();
    }
  }();
}