Flutter Listview从视频URL加载缩略图时冻结,我的应用程序崩溃了

时间:2019-10-12 13:43:41

标签: android listview flutter thumbnails

我尝试滚动列表时从视频URL获取图像,但是当我使用视频缩略图库并在应用列表中调用它冻结时,应用崩溃了,这是我的代码

  Future _loadMore(context) async {

final diractory=Provider.of<DiractoryPath>(context,listen: false);
Provider.of<LoadState>(context).setLoadState(true);
final index= Provider.of<IndexLazyloading>(context);


if(moves.length!=index.oldmove){
  resetlist(context);

}
// Add in an artificial delay


for (var i = index.currentindex; i <= index.currentindex + increment && i<moves.length; i++) {

  File f=new File( "${diractory.diractory}/${moves[i].videourl.split("/").last.replaceAll("mp4", "png")}");
 if(!f.existsSync())
await getimage("${strings.baseurl}/videos/${moves[i].videourl}",context);
  index.setdata(i);
}
await new Future.delayed(const Duration(seconds: 2));
Provider.of<LoadState>(context).setLoadState(false);
index.setcurrentIndex(index.data.length)  ;
index.setoldMove(moves.length);

}

这是我使用的插件

Future<Null> getimage(videourl,context)async{
 final uint8list = await VideoThumbnail.thumbnailFile(
 video: videourl,
thumbnailPath: Provider.of<DiractoryPath>(context).diractory,
imageFormat: ImageFormat.WEBP,
maxHeightOrWidth: 0, // the original resolution of the video
quality: 75,
 );
}

我尝试使用png,但不起作用 这是我调用此函数的列表,此代码有什么问题,请帮助我

 LazyLoadScrollView(
    isLoading: loadstate.isload,
    onEndOfPage: () => _loadMore(context),
child: ListView.builder(
itemCount: indexlayze.data.length,
itemBuilder: (context, position) {
return _buildProductItem(context,position);
},
));

我的列表到达列表末尾时会得到10张图片缩略图,但是处理起来很慢

1 个答案:

答案 0 :(得分:0)

如何将这项工作专用于云上运行的NGINX / NodeJS服务?让该应用程序从中下载缩略图。这是我以前所做的。

如果您确实需要通过App生成缩略图,请尝试以下几点:

  • 使用JPG / PNG代替WebP,因为它在iOS上花费很多CPU
  • 创建列表或流以将请求排队,在完成之前显示占位符缩略图。
  • 一旦ListView停止滚动,就将队列优先。
  • 缩略图完成后,对图像组件进行信号传输,同时使用下一项来调用缩略图