Commit 9366adbc3e6b25bc1a6122a4fc463ae21efd20b8

Authored by wdn127929
1 parent 9b68d353

修复评论管理页面视频封面显示问题

@@ -18,19 +18,19 @@ if (flutterRoot == null) { @@ -18,19 +18,19 @@ if (flutterRoot == null) {
18 18
19 19
20 20
21 -def flutterVersionCode = "512" 21 +def flutterVersionCode = "513"
22 if (flutterVersionCode == null) { 22 if (flutterVersionCode == null) {
23 - flutterVersionCode = '512' 23 + flutterVersionCode = '513'
24 24
25 25
26 26
27 } 27 }
28 28
29 29
30 -def flutterVersionName = "5.1.2" 30 +def flutterVersionName = "5.1.3"
31 31
32 if (flutterVersionName == null) { 32 if (flutterVersionName == null) {
33 - flutterVersionName = '5.1.2' 33 + flutterVersionName = '5.1.3'
34 34
35 35
36 } 36 }
1 import 'dart:convert'; 1 import 'dart:convert';
2 2
  3 +import 'package:cached_video_player/cached_video_player.dart';
3 import 'package:common_utils/common_utils.dart'; 4 import 'package:common_utils/common_utils.dart';
4 5
5 class CommentsModel { 6 class CommentsModel {
@@ -210,6 +211,8 @@ class CommentsImageModel { @@ -210,6 +211,8 @@ class CommentsImageModel {
210 ImageAve imageAve; 211 ImageAve imageAve;
211 String url; 212 String url;
212 String avinfo; 213 String avinfo;
  214 + CachedVideoPlayerController videoPlayerController;
  215 + Future initializeVideoPlayerFuture;
213 216
214 CommentsImageModel( 217 CommentsImageModel(
215 {this.key, 218 {this.key,
  1 +import 'dart:io';
1 import 'dart:ui'; 2 import 'dart:ui';
2 3
3 import 'package:cached_network_image/cached_network_image.dart'; 4 import 'package:cached_network_image/cached_network_image.dart';
@@ -16,6 +17,7 @@ import 'package:one_key/widgets/h_empty_view.dart'; @@ -16,6 +17,7 @@ import 'package:one_key/widgets/h_empty_view.dart';
16 import 'package:one_key/widgets/round_button.dart'; 17 import 'package:one_key/widgets/round_button.dart';
17 import 'package:one_key/widgets/system_app_bar.dart'; 18 import 'package:one_key/widgets/system_app_bar.dart';
18 import 'package:one_key/widgets/v_empty_view.dart'; 19 import 'package:one_key/widgets/v_empty_view.dart';
  20 +import 'package:path_provider/path_provider.dart';
19 import 'package:provider/provider.dart'; 21 import 'package:provider/provider.dart';
20 import 'package:video_player/video_player.dart'; 22 import 'package:video_player/video_player.dart';
21 23
@@ -30,6 +32,7 @@ import '../../online_check/photo_view_wiget.dart'; @@ -30,6 +32,7 @@ import '../../online_check/photo_view_wiget.dart';
30 // import 'package:fijkplayer/fijkplayer.dart'; 32 // import 'package:fijkplayer/fijkplayer.dart';
31 // import 'package:video_thumbnail/video_thumbnail.dart'; 33 // import 'package:video_thumbnail/video_thumbnail.dart';
32 import 'package:cached_video_player/cached_video_player.dart'; 34 import 'package:cached_video_player/cached_video_player.dart';
  35 +import 'package:video_thumbnail/video_thumbnail.dart';
33 36
34 /** 37 /**
35 * 评价管理 38 * 评价管理
@@ -48,12 +51,6 @@ class _CommentManageHomePageState extends State<CommentManageHomePage> { @@ -48,12 +51,6 @@ class _CommentManageHomePageState extends State<CommentManageHomePage> {
48 String label = ''; 51 String label = '';
49 52
50 TextEditingController replyController = TextEditingController(); 53 TextEditingController replyController = TextEditingController();
51 - // 声明控制器(两个)  
52 - CachedVideoPlayerController videoPlayerController;  
53 - // ChewieController chewieController;  
54 - // final FijkPlayer player = FijkPlayer();  
55 - // VideoPlayerController _controller;  
56 - Future _initializeVideoPlayerFuture;  
57 54
58 @override 55 @override
59 void initState() { 56 void initState() {
@@ -181,6 +178,19 @@ class _CommentManageHomePageState extends State<CommentManageHomePage> { @@ -181,6 +178,19 @@ class _CommentManageHomePageState extends State<CommentManageHomePage> {
181 // return data; 178 // return data;
182 // } 179 // }
183 180
  181 + Future<String> getThumbnailFile(
  182 + List<CommentsImageModel> imags, int index) async {
  183 + final fileName = await VideoThumbnail.thumbnailFile(
  184 + video: imags[index].url,
  185 + thumbnailPath: (await getTemporaryDirectory()).path,
  186 + // imageFormat: ImageFormat.WEBP,
  187 + // maxHeight:
  188 + // 64, // specify the height of the thumbnail, let the width auto-scaled to keep the source aspect ratio
  189 + quality: 100,
  190 + );
  191 + return fileName;
  192 + }
  193 +
184 /// 九宫格 194 /// 九宫格
185 Widget _getGridImg(List<CommentsImageModel> imags) { 195 Widget _getGridImg(List<CommentsImageModel> imags) {
186 imags.removeWhere((element) => element.url == null || element.url == ''); 196 imags.removeWhere((element) => element.url == null || element.url == '');
@@ -201,59 +211,143 @@ class _CommentManageHomePageState extends State<CommentManageHomePage> { @@ -201,59 +211,143 @@ class _CommentManageHomePageState extends State<CommentManageHomePage> {
201 //子组件宽高长度比例 211 //子组件宽高长度比例
202 childAspectRatio: 1.0), 212 childAspectRatio: 1.0),
203 itemBuilder: (BuildContext context, int index) { 213 itemBuilder: (BuildContext context, int index) {
204 - if (imags[index].avinfo != null) {  
205 - videoPlayerController =  
206 - CachedVideoPlayerController.network(imags[index].url);  
207 - videoPlayerController.setLooping(false);  
208 - _initializeVideoPlayerFuture = videoPlayerController.initialize(); 214 + if (imags[index].avinfo != null &&
  215 + imags[index].avinfo != 'false' &&
  216 + imags[index].avinfo != '0') {
  217 + // 声明控制器(两个)
  218 + // imags[index].videoPlayerController =
  219 + // CachedVideoPlayerController.network(imags[index].url);
  220 + // // ChewieController chewieController;
  221 + // // final FijkPlayer player = FijkPlayer();
  222 + // // VideoPlayerController _controller;
  223 + // imags[index].initializeVideoPlayerFuture =
  224 + // imags[index].videoPlayerController.initialize();
  225 +
  226 + // imags[index].videoPlayerController.setLooping(false);
  227 +
  228 + // final fileName = _getThumbnailFile(imags, index);
209 229
210 //视频 230 //视频
211 - return InkWell(  
212 - onTap: () {  
213 - Navigator.push(  
214 - context,  
215 - PopRoute(  
216 - child: VideoPage(  
217 - url: imags[index].url,  
218 - )));  
219 - },  
220 - child: Stack(alignment: Alignment.center, children: [  
221 - ClipRRect(  
222 - borderRadius: BorderRadius.circular(r(8)),  
223 - child: FutureBuilder(  
224 - //显示缩略图  
225 - future: _initializeVideoPlayerFuture,  
226 - builder: (context, snapshot) {  
227 - print(snapshot.connectionState);  
228 - if (snapshot.hasError) print(snapshot.error);  
229 - if (snapshot.connectionState ==  
230 - ConnectionState.done) {  
231 - return AspectRatio(  
232 - aspectRatio: 1 / 1,  
233 - // aspectRatio: _controller.value.aspectRatio,  
234 - // child: VideoPlayer(videoPlayerController),  
235 - child:  
236 - CachedVideoPlayer(videoPlayerController));  
237 - } else {  
238 - return Center(  
239 - child: CircularProgressIndicator(),  
240 - );  
241 - }  
242 - },  
243 - )),  
244 - Positioned(  
245 - child: Image.asset(  
246 - Utils.getImgPath('play'),  
247 - width: w(20),  
248 - ))  
249 - ])); 231 + return FutureBuilder<String>(
  232 + future: getThumbnailFile(imags, index),
  233 + builder: (BuildContext context, AsyncSnapshot snapshot) {
  234 + if (snapshot.hasData) {
  235 + return InkWell(
  236 + onTap: () {
  237 + Navigator.push(
  238 + context,
  239 + PopRoute(
  240 + child: VideoPage(
  241 + url: imags[index].url,
  242 + )));
  243 + },
  244 + child: Stack(alignment: Alignment.center, children: [
  245 + ClipRRect(
  246 + borderRadius: BorderRadius.circular(r(8)),
  247 + child: AspectRatio(
  248 + // borderRadius: BorderRadius.circular(r(8)),
  249 + aspectRatio: 1,
  250 + child: Image.file(
  251 + File(snapshot.data),
  252 + fit: BoxFit.cover,
  253 + scale: 1,
  254 + ),
  255 +
  256 + // width: w(),
  257 + // height: ScreenUtil().setWidth(100 * 2),
  258 + )),
  259 + Positioned(
  260 + child: Image.asset(
  261 + Utils.getImgPath('play'),
  262 + width: w(20),
  263 + ))
  264 + ]));
  265 + } else if (snapshot.hasError) {
  266 + return SizedBox();
  267 + // return Center(
  268 + // child: CircularProgressIndicator(),
  269 + // );
  270 + } else {
  271 + return SizedBox();
  272 + // return Center(
  273 + // child: CircularProgressIndicator(),
  274 + // );
  275 + }
  276 + },
  277 + );
  278 + // return InkWell(
  279 + // onTap: () {
  280 + // Navigator.push(
  281 + // context,
  282 + // PopRoute(
  283 + // child: VideoPage(
  284 + // url: imags[index].url,
  285 + // )));
  286 + // },
  287 + // child: Stack(alignment: Alignment.center, children: [
  288 + // ClipRRect(
  289 + // borderRadius: BorderRadius.circular(r(8)),
  290 + // child: CachedNetworkImage(
  291 + // imageUrl: fileName,
  292 + // fit: BoxFit.cover,
  293 +
  294 + // // width: w(),
  295 + // // height: ScreenUtil().setWidth(100 * 2),
  296 + // ),
  297 + // )
  298 + // // ClipRRect(
  299 + // // borderRadius: BorderRadius.circular(r(8)),
  300 + // // child: FutureBuilder(
  301 + // // //显示缩略图
  302 + // // future: imags[index].initializeVideoPlayerFuture,
  303 + // // builder: (context, snapshot) {
  304 + // // print(snapshot.connectionState);
  305 + // // if (snapshot.hasError) print(snapshot.error);
  306 + // // if (snapshot.connectionState ==
  307 + // // ConnectionState.done) {
  308 + // // ClipRRect(
  309 + // // borderRadius: BorderRadius.circular(r(8)),
  310 + // // child: CachedNetworkImage(
  311 + // // imageUrl: fileName,
  312 + // // fit: BoxFit.cover,
  313 +
  314 + // // // width: w(),
  315 + // // // height: ScreenUtil().setWidth(100 * 2),
  316 + // // ),
  317 + // // );
  318 + // // // return ClipRRect(
  319 + // // // borderRadius: BorderRadius.circular(r(8)),
  320 + // // // // aspectRatio: 1 / 1,
  321 + // // // // aspectRatio: imags[index]
  322 + // // // // .videoPlayerController
  323 + // // // // .value
  324 + // // // // .aspectRatio,
  325 + // // // // child: VideoPlayer(videoPlayerController),
  326 + // // // // child: CachedVideoPlayer(
  327 + // // // // imags[index].videoPlayerController)
  328 + // // // );
  329 + // // } else {
  330 + // // return Center(
  331 + // // child: CircularProgressIndicator(),
  332 + // // );
  333 + // // }
  334 + // // },
  335 + // // )),
  336 + // Positioned(
  337 + // child: Image.asset(
  338 + // Utils.getImgPath('play'),
  339 + // width: w(20),
  340 + // ))
  341 + // ]));
250 } 342 }
251 343
252 return InkWell( 344 return InkWell(
253 onTap: () { 345 onTap: () {
254 List<String> images = []; 346 List<String> images = [];
255 imags.forEach((element) { 347 imags.forEach((element) {
256 - if (!element.mimeType.startsWith('video')) { 348 + if (element.avinfo == null ||
  349 + element.avinfo == 'false' ||
  350 + element.avinfo == '0') {
257 images.add(element.url); 351 images.add(element.url);
258 } 352 }
259 }); 353 });
@@ -1505,6 +1505,13 @@ packages: @@ -1505,6 +1505,13 @@ packages:
1505 url: "https://pub.flutter-io.cn" 1505 url: "https://pub.flutter-io.cn"
1506 source: hosted 1506 source: hosted
1507 version: "2.0.10" 1507 version: "2.0.10"
  1508 + video_thumbnail:
  1509 + dependency: "direct main"
  1510 + description:
  1511 + name: video_thumbnail
  1512 + url: "https://pub.flutter-io.cn"
  1513 + source: hosted
  1514 + version: "0.5.3"
1508 wakelock: 1515 wakelock:
1509 dependency: transitive 1516 dependency: transitive
1510 description: 1517 description:
@@ -145,7 +145,7 @@ dependencies: @@ -145,7 +145,7 @@ dependencies:
145 #苹果登陆 145 #苹果登陆
146 # sign_in_with_apple: ^3.0.0 146 # sign_in_with_apple: ^3.0.0
147 sign_in_with_apple: 4.2.0 147 sign_in_with_apple: 4.2.0
148 - # video_thumbnail: ^0.5.3 148 + video_thumbnail: ^0.5.3
149 # video_player: ^2.4.7 149 # video_player: ^2.4.7
150 # video_player: ^2.7.0 150 # video_player: ^2.7.0
151 # video_player: ^2.4.2 151 # video_player: ^2.4.2