This plugin generates thumbnail from video file or URL. It returns image in memory or writes into a file. It offers rich options to control the image format, resolution and quality. Supports iOS and Android.
I REALLY can not make your package work for me its so frustrating !!
I have a video url and I wanted a thumbnail for it this is what I did
class ThumbnailRequest {
final String video;
final String thumbnailPath;
final ImageFormat imageFormat;
final int maxHeight;
final int maxWidth;
final int timeMs;
final int quality;
class ThumbnailResult {
final Image image;
final int dataSize;
final int height;
final int width;
const ThumbnailResult({this.image, this.dataSize, this.height, this.width});
}
I REALLY can not make your package work for me its so frustrating !!
I have a video url and I wanted a thumbnail for it this is what I did
class ThumbnailRequest { final String video; final String thumbnailPath; final ImageFormat imageFormat; final int maxHeight; final int maxWidth; final int timeMs; final int quality;
const ThumbnailRequest( {this.video, this.thumbnailPath, this.imageFormat, this.maxHeight, this.maxWidth, this.timeMs, this.quality}); }
class ThumbnailResult { final Image image; final int dataSize; final int height; final int width; const ThumbnailResult({this.image, this.dataSize, this.height, this.width}); }
Future genThumbnail(ThumbnailRequest r) async {
//WidgetsFlutterBinding.ensureInitialized();
Uint8List bytes;
final Completer completer = Completer();
if (r.thumbnailPath != null) {
final thumbnailPath = await VideoThumbnail.thumbnailFile(
video: r.video,
thumbnailPath: r.thumbnailPath,
imageFormat: r.imageFormat,
maxHeight: r.maxHeight,
maxWidth: r.maxWidth,
timeMs: r.timeMs,
quality: r.quality);
} else { bytes = await VideoThumbnail.thumbnailData( video: r.video, imageFormat: r.imageFormat, maxHeight: r.maxHeight, maxWidth: r.maxWidth, timeMs: r.timeMs, quality: r.quality); }
int _imageDataSize = bytes.length; print("image size: $_imageDataSize");
final _image = Image.memory(bytes); image.image .resolve(ImageConfiguration()) .addListener(ImageStreamListener((ImageInfo info, bool ) { completer.complete(ThumbnailResult( image: _image, dataSize: _imageDataSize, height: info.image.height, width: info.image.width, )); })); return completer.future; }
and to show I used this
FutureBuilder(
future: genThumbnail(ThumbnailRequest(
video: e,
thumbnailPath: tempPath,
imageFormat: ImageFormat.JPEG,
maxHeight:
64, // specify the height of the thumbnail, let the width auto-scaled to keep the source aspect ratio
quality: 75,
)),
builder: (BuildContext context,
AsyncSnapshot snapshot) {
if (snapshot.hasData) {
final _image = snapshot.data.image;
final _width = snapshot.data.width;
final _height = snapshot.data.height;
final _dataSize = snapshot.data.dataSize;
return Column(
mainAxisAlignment:
MainAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
Container(
color: Colors.grey,
height: 1.0,
),
_image,
],
);
} else if (snapshot.hasError) {
return Container(
padding: EdgeInsets.all(8.0),
color: Colors.red,
child: Text(
"Error:\n${snapshot.error.toString()}",
),
);
} else {
return Column(
mainAxisAlignment:
MainAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
SizedBox(
height: 10.0,
),
CircularProgressIndicator(),
]);
}
},
)
and to get temp Directory I did
String tempPath; getTempDirectory() async { Directory tempDir = await getTemporaryDirectory(); tempPath = tempDir.path; }
@override void initState() { getTempDirectory(); super.initState(); }
and the app crashes PLEASE help me out