Ver código fonte

优化游戏详情页先显示封面,点击再加载视频

kidd3166 1 ano atrás
pai
commit
64d1dc7c14
2 arquivos alterados com 49 adições e 11 exclusões
  1. 40 8
      lib/pages/game/game_detail.dart
  2. 9 3
      lib/provider/bluetooth.dart

+ 40 - 8
lib/pages/game/game_detail.dart

@@ -1219,7 +1219,7 @@ class __VideoWidgetState extends State<_VideoWidget> {
   void initState() {
     super.initState();
 
-    controller = VideoPlayerController.network(widget.data.introduceVideo ?? "")..initialize();
+    controller = VideoPlayerController.network(widget.data.introduceVideo ?? "");
     controller.setLooping(true);
     if (controller.value.isPlaying == true) {
       overlay();
@@ -1313,13 +1313,17 @@ class __VideoWidgetState extends State<_VideoWidget> {
                                       height: 50.0,
                                     ),
                                     onTap: () {
-                                      if (v.isPlaying) {
-                                        controller.pause();
-                                      } else {
-                                        if (controller.value.position.compareTo(controller.value.duration) == 0) {
-                                          controller.seekTo(Duration.zero);
+                                      if(controller.value.isInitialized) {
+                                        if (v.isPlaying) {
+                                          controller.pause();
+                                        } else {
+                                          if (controller.value.position.compareTo(controller.value.duration) == 0) {
+                                            controller.seekTo(Duration.zero);
+                                          }
+                                          controller.play();
                                         }
-                                        controller.play();
+                                      }else{
+                                        controller.initialize().then((value) => controller.play());
                                       }
                                       overlay();
                                     },
@@ -1356,8 +1360,36 @@ class __VideoWidgetState extends State<_VideoWidget> {
                           ),
                         ),
                       );
-                    } else {
+                    }else if(v.isBuffering) {
                       return Center(child: CircularProgressIndicator());
+                    } else {
+                      return Container(
+                        width: double.infinity,
+                        height: double.infinity,
+                        child: Stack(
+                          fit: StackFit.expand,
+                          children: <Widget>[
+                            CachedNetworkImage(imageUrl: '${widget.data.introduceVideoCover}', fit: BoxFit.fitWidth,),
+                            Container(
+                              width: double.infinity,
+                              height: double.infinity,
+                              decoration: BoxDecoration(color: const Color(0xFF040404).withOpacity(.05)),
+                            ),
+                            Center(
+                              child: InkWell(
+                                child: Image.asset(
+                                  "lib/assets/img/game_icon_play.png",
+                                  height: 50.0,
+                                ),
+                                onTap: () {
+                                  controller.initialize().then((value) => controller.play());
+                                  overlay();
+                                },
+                              ),
+                            ),
+                          ],
+                        ),
+                      );
                     }
                   }),
               if (widget.isFullScreen)

+ 9 - 3
lib/provider/bluetooth.dart

@@ -90,8 +90,12 @@ class Bluetooth with InjectApi, GameLog {
     characteristicWrite = null;
     characteristicNotify = null;
     if(_streamSubscriptions.isNotEmpty) {
-      for (StreamSubscription<dynamic> subscription in _streamSubscriptions) {
-        await subscription.cancel();
+      try {
+        for (StreamSubscription<dynamic> subscription in _streamSubscriptions) {
+                await subscription.cancel();
+              }
+      } catch (e) {
+        print(e);
       }
     }
     _streamSubscriptions.clear();
@@ -603,7 +607,9 @@ class Bluetooth with InjectApi, GameLog {
       await Future.delayed(Duration(seconds: 3));
     }
 
-    await disconnectDevice("断开蓝牙连接 $_connecting");
+    if(_connecting) {
+      await disconnectDevice("断开蓝牙连接 $_connecting");
+    }
 
     //
     // notifyConnectTime("F");