generateThumbnail method
Implementation
Stream<List<Uint8List>> generateThumbnail() async* {
final String _videoPath = videoFile.path;
double _eachPart = videoDuration / numberOfThumbnails;
List<Uint8List> _byteList = [];
// the cache of last thumbnail
late Uint8List _lastBytes;
for (int i = 1; i <= numberOfThumbnails; i++) {
Uint8List? _bytes;
_bytes = await VideoThumbnail.thumbnailData(
video: _videoPath,
imageFormat: ImageFormat.JPEG,
timeMs: (_eachPart * i).toInt(),
quality: quality,
);
// if current thumbnail is null use the last thumbnail
if (_bytes != null) {
_lastBytes = _bytes;
} else {
_bytes = _lastBytes;
}
_byteList.add(_bytes);
yield _byteList;
}
}