screenshot method

  1. @override
Future<Uint8List?> screenshot({
  1. String? format = 'image/jpeg',
  2. bool synchronized = true,
})
override

Takes the snapshot of the current video frame & returns encoded image bytes as Uint8List.

The format parameter specifies the format of the image to be returned. Supported values are:

  • image/jpeg: Returns a JPEG encoded image.
  • image/png: Returns a PNG encoded image.
  • null: Returns BGRA pixel buffer.

Implementation

@override
Future<Uint8List?> screenshot(
    {String? format = 'image/jpeg', bool synchronized = true}) async {
  Future<Uint8List?> function() async {
    if (![
      'image/jpeg',
      'image/png',
      null,
    ].contains(format)) {
      throw ArgumentError.value(
        format,
        'format',
        'Supported values are: image/jpeg, image/png, null',
      );
    }
    if (disposed) {
      throw AssertionError('[Player] has been disposed');
    }

    await waitForPlayerInitialization;
    await waitForVideoControllerInitializationIfAttached;

    return compute(
      _screenshot,
      _ScreenshotData(
        ctx.address,
        NativeLibrary.path,
        format,
      ),
    );
  }

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