justsoft / video_thumbnail

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.
MIT License
183 stars 238 forks source link

ITS SO FRUSTRATING TO MAKE IT WORK #92

Closed developer-farhan closed 2 years ago

developer-farhan commented 2 years ago

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);

print("thumbnail file is located: $thumbnailPath");

final file = File(thumbnailPath);
bytes = file.readAsBytesSync();

} 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

justsoft commented 2 years ago

Have you even read the example app? Please do it first.