【问题标题】:Flutter Listview freezes while it is loading thumbnail images from video url and my app crashedFlutter Listview 在从视频 url 加载缩略图时冻结,我的应用程序崩溃了
【发布时间】:2020-02-09 18:42:45
【问题描述】:

当我的列表滚动时,我尝试从视频 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 个图像缩略图,但如何处理它非常慢

【问题讨论】:

    标签: android listview flutter thumbnails


    【解决方案1】:

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

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

    • 使用 JPG/PNG 而不是 WebP,因为它在 iOS 上会消耗大量 CPU
    • 创建列表或流以对请求进行排队,在完成之前显示占位符缩略图。
    • ListView 停止滚动后优先队列。
    • 缩略图完成后向图像组件发出信号,同时获取下一项调用缩略图

    【讨论】:

    • 我不知道如何处理您的指南,请给我发送代码示例,了解如何为图像和请求创建占位符和队列
    猜你喜欢
    • 1970-01-01
    • 2012-06-14
    • 1970-01-01
    • 1970-01-01
    • 2022-11-03
    • 2020-04-19
    • 1970-01-01
    • 2020-08-17
    • 1970-01-01
    相关资源
    最近更新 更多