如何使视频缩略图抖动?

时间:2018-10-16 14:42:57

标签: dart flutter

我有一个Flutter应用,可显示内部存储中的视频文件列表... 现在我想在视频列表中显示视频的缩略图,那么如何在我的Flutter应用中做到这一点? / em> 如果有人有任何想法,请帮助我。

我正在使用ListBuilder小部件。

4 个答案:

答案 0 :(得分:1)

  1. 使用缩略图插件-https://pub.dartlang.org/packages/thumbnails
  2. 创建一个文件夹以将所有缩略图存储在手机存储中。
  3. 将此代码添加到一个函数中,

    code:String thumb = await Thumbnails.getThumbnail(
    thumbnailFolder: folderPath,
    videoFile: videoPathUrl,
    imageType: ThumbFormat.PNG,//this image will store in created folderpath
    quality: 30);
    
  4. 现在显示该图像放在一个容器中,并打开该container/widgetopen/play视频的视频网址。

答案 1 :(得分:1)

您也可以使用video_thumbnail插件,如下所示:

final uint8list = await VideoThumbnail.thumbnailData(
  video: videofile.path,
  imageFormat: ImageFormat.JPEG,
  maxWidth: 128, // specify the width of the thumbnail, let the height auto-scaled to keep the source aspect ratio
  quality: 25,
);

对于视频文件

OR

final uint8list = await VideoThumbnail.thumbnailFile(
  video: "https://flutter.github.io/assets-for-api-docs/assets/videos/butterfly.mp4",
  thumbnailPath: (await getTemporaryDirectory()).path,
  imageFormat: ImageFormat.WEBP,
  maxHeight: 64, // specify the height of the thumbnail, let the width auto-scaled to keep the source aspect ratio
  quality: 75,
);

来自视频网址

答案 2 :(得分:0)

对于其他人。使用video player插件作为缩略图。这对于那些库非常有效,并且也适用于ios。只需像创建item一样创建statefullWidget(如果要在列表中显示,则将该小部件用作item)。参见下面的示例。

class _VideoItemState extends State<VideoItem> {
VideoPlayerController _controller;

@override
void initState() {
super.initState();
_controller = VideoPlayerController.network(widget.video.file.path)
  ..initialize().then((_) {
    setState(() {});  //when your thumbnail will show.
  });
}

@override
void dispose() {
super.dispose();
_controller.dispose();
}

@override
Widget build(BuildContext context) {
return ListTile(
  leading: _controller.value.initialized
      ? Container(
          width: 100.0,
          height: 56.0,
          child: VideoPlayer(_controller),
        )
      : CircularProgressIndicator(),
  title: Text(widget.video.file.path.split('/').last),
  onTap: () {
    Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) =>
            VideoPlayerPage(videoUrl: widget.video.file.path),
      ),
    );
  },
);
 }
}

答案 3 :(得分:-1)

这里是一个软件包,它增加了生成缩略图的功能: https://pub.dartlang.org/packages/thumbnails

不幸的是,它仅支持Android。