浏览代码

添加视频开启关闭快速控制功能(默认关闭)

hwh97 6 年之前
父节点
当前提交
4f57a482ef
共有 3 个文件被更改,包括 29 次插入4 次删除
  1. 2 1
      example/lib/main.dart
  2. 4 0
      example/pubspec.yaml
  3. 23 3
      lib/src/i2_material_controls.dart

+ 2 - 1
example/lib/main.dart

@@ -41,7 +41,8 @@ class _ChewieDemoState extends State<ChewieDemo> {
           aspectRatio: _videoPlayerController1.value.aspectRatio,
           autoPlay: true,
           looping: true,
-          customControls: I2MaterialControls(),
+          customControls: I2MaterialControls(
+          ),
         );
         setState(() {
         });

+ 4 - 0
example/pubspec.yaml

@@ -4,6 +4,10 @@ description: An example of how to use the chewie for Flutter
 dependencies:
   chewie:
     path: ../
+#  chewie:
+    #    path: ../plugins/chewie/
+#    git:
+#      url: https://git.i2erp.cn/plugins/video_chewie.git
   video_player: ^0.10.0+2
   auto_orientation: ^0.0.2
   flutter:

+ 23 - 3
lib/src/i2_material_controls.dart

@@ -11,8 +11,9 @@ import 'package:sys_volume/flutter_volume.dart';
 import 'package:video_player/video_player.dart';
 
 class I2MaterialControls extends StatefulWidget {
+  final bool enableQuickControl;
 
-  const I2MaterialControls({Key key}) : super(key: key);
+  const I2MaterialControls({Key key, this.enableQuickControl = false}) : super(key: key);
 
   @override
   State<StatefulWidget> createState() {
@@ -79,7 +80,9 @@ class _MaterialControlsState extends State<I2MaterialControls> {
       child: GestureDetector(
         onTap: () => _cancelAndRestartTimer(),
         onVerticalDragStart: (DragStartDetails details) async {
-          print("onVerticalDragStart ${details.globalPosition}");
+          if (!widget.enableQuickControl) {
+            return;
+          }
           // 判断距离 只响应2/5的左边和2/5的右边
           if (details.globalPosition.dx < MediaQuery.of(context).size.width / 5 * 2) {
             // 响应亮度
@@ -103,7 +106,9 @@ class _MaterialControlsState extends State<I2MaterialControls> {
           }
         },
         onVerticalDragUpdate: (DragUpdateDetails details) async {
-          print("onVerticalDragUpdate ${details.globalPosition}");
+          if (!widget.enableQuickControl) {
+            return;
+          }
           if (_verticalMode != null) {
             // 显示数值(百分比)
             setState(() {
@@ -152,6 +157,9 @@ class _MaterialControlsState extends State<I2MaterialControls> {
           }
         },
         onVerticalDragEnd: (DragEndDetails details){
+          if (!widget.enableQuickControl) {
+            return;
+          }
           setState(() {
             _verticalMode = null;
             currentBright = null;
@@ -160,12 +168,18 @@ class _MaterialControlsState extends State<I2MaterialControls> {
           });
         },
         onHorizontalDragStart: (DragStartDetails detail) {
+          if (!widget.enableQuickControl) {
+            return;
+          }
           if (_latestValue.duration == null) return;
           _cancelAndRestartTimer();
           startDx = detail.localPosition.dx;
           dragDuration = _latestValue.position;
         },
         onHorizontalDragUpdate: (DragUpdateDetails detail) {
+          if (!widget.enableQuickControl) {
+            return;
+          }
           if (_latestValue.duration == null) return;
           _cancelAndRestartTimer();
           lastDx = detail.localPosition.dx;
@@ -177,6 +191,9 @@ class _MaterialControlsState extends State<I2MaterialControls> {
           });
         },
         onHorizontalDragCancel: (){
+          if (!widget.enableQuickControl) {
+            return;
+          }
           startDx = null;
           lastDx = null;
           dragDuration = null;
@@ -185,6 +202,9 @@ class _MaterialControlsState extends State<I2MaterialControls> {
           });
         },
         onHorizontalDragEnd: (DragEndDetails detail) {
+          if (!widget.enableQuickControl) {
+            return;
+          }
           if (startDx != null && lastDx != null && _latestValue.duration != null && dragDuration != null) {
             Duration finalDuration = getDragDuration();
             chewieController.seekTo(finalDuration);