getSnapshot method

Future<Snapshot?> getSnapshot()

Pauses the video and returns a Snapshot.

Implementation

Future<Snapshot?> getSnapshot() async {
  player.pause();
  VideoFrame? frame;
  final future = Completer();
  final sub = player.imageStream!.listen(null);
  sub.onData((event) {
    future.complete(event);
    sub.cancel();
  });
  player.pulse();

  frame = await future.future;
  Snapshot snapshot;
  if (frame != null && frame.size > 0) {
    snapshot = Snapshot(
      image: (await frame.content!.image
              .toByteData(format: ui.ImageByteFormat.png))!
          .buffer
          .asUint8List(),
      name: '${player.metadata?.filename}-${frame.pts}',
    );
    return snapshot;
  }

  return null;
}