VideoController constructor
VideoController(
- Player player, {
- 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:
- You can limit size of the video output by specifying VideoControllerConfiguration.width & VideoControllerConfiguration.height.
- A smaller width & height may yield substantial performance improvements.
- By default, both VideoControllerConfiguration.height & VideoControllerConfiguration.width are
null
i.e. output is based on video's resolution.
- You can switch between GPU & CPU rendering by specifying VideoControllerConfiguration.enableHardwareAcceleration.
- Disabling the option may improve stability on certain devices.
- By default, VideoControllerConfiguration.enableHardwareAcceleration is
true
i.e. GPU (Direct3D/OpenGL/METAL) is utilized.
Platform specific limitations & differences:
Android
- VideoControllerConfiguration.width & VideoControllerConfiguration.height arguments have no effect.
Web
- VideoControllerConfiguration.width & VideoControllerConfiguration.height arguments have no effect.
- Only single Video output can be displayed for a VideoController. Displaying multiple Video widgets with same VideoController will cause only last mounted Video to be displayed.
- VideoControllerConfiguration.enableHardwareAcceleration is ignored i.e. GPU usage is dependent upon the web browser.
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();
}
}();
}