VideoController constructor

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

VideoController

VideoController is used to initialize & display video output. It takes reference to existing Player instance from package:media_kit.

Passing VideoController to Video widget will cause the video output to be displayed.

late final player = Player();
late final controller = VideoController(player);

Configurable options:

  1. You can limit size of the video output by specifying VideoControllerConfiguration.width & VideoControllerConfiguration.height.
  2. You can switch between GPU & CPU rendering by specifying VideoControllerConfiguration.enableHardwareAcceleration.

Platform specific limitations & differences:

Android

Web

Implementation

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

  () async {
    try {
      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;
      } else if (WebVideoController.supported) {
        final result = await WebVideoController.create(
          player,
          configuration,
        );
        platform.complete(result);
        notifier.value = result;
      }

      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.',
          ),
        );
      }
    } catch (exception, stacktrace) {
      platform.completeError(exception);
      debugPrint(exception.toString());
      debugPrint(stacktrace.toString());
    }

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