Преглед изворни кода

使用EventBus控制快捷操作的显示

hwh97 пре 6 година
родитељ
комит
bf6e4f3da2

+ 5 - 3
example/lib/main.dart

@@ -45,10 +45,14 @@ class _ChewieDemoState extends State<ChewieDemo> {
   VideoPlayerController _videoPlayerController2;
   ChewieController _chewieController;
   double aspectRatio=1;
+  I2MaterialControls _i2materialControls;
 
   @override
   void initState() {
     super.initState();
+    _i2materialControls = I2MaterialControls(
+      enableQuickControl: true,
+    );
     _videoPlayerController1 = VideoPlayerController.network(
         'http://mirror.aarnet.edu.au/pub/TED-talks/911Mothers_2010W-480p.mp4')
       ..initialize().then((_){
@@ -58,9 +62,7 @@ class _ChewieDemoState extends State<ChewieDemo> {
           aspectRatio: _videoPlayerController1.value.aspectRatio,
           autoPlay: true,
           looping: true,
-          customControls: I2MaterialControls(
-            enableQuickControl: true,
-          ),
+          customControls: _i2materialControls,
         );
         setState(() {
         });

+ 1 - 0
lib/chewie.dart

@@ -3,3 +3,4 @@ library chewie;
 export 'src/chewie_player.dart';
 export 'src/chewie_progress_colors.dart';
 export 'src/i2_material_controls.dart';
+export 'src/i2_control_event.dart';

+ 1 - 0
lib/src/chewie_player.dart

@@ -130,6 +130,7 @@ class ChewieState extends State<Chewie> {
     );
 
     SystemChrome.setEnabledSystemUIOverlays([]);
+    /// ?????????????????????????????????????
     if (isAndroid) {
       SystemChrome.setPreferredOrientations([
         DeviceOrientation.landscapeLeft,

+ 7 - 0
lib/src/i2_control_event.dart

@@ -0,0 +1,7 @@
+import 'package:event_bus/event_bus.dart';
+
+EventBus i2ControlEventBus = EventBus();
+
+enum I2ControllerEvent {
+  ShowControl,
+}

+ 21 - 3
lib/src/i2_material_controls.dart

@@ -2,6 +2,7 @@ import 'dart:async';
 
 import 'package:chewie/src/chewie_player.dart';
 import 'package:chewie/src/chewie_progress_colors.dart';
+import 'package:chewie/src/i2_control_event.dart';
 import 'package:chewie/src/material_progress_bar.dart';
 import 'package:chewie/src/utils.dart';
 import 'package:flutter/material.dart';
@@ -17,7 +18,7 @@ class I2MaterialControls extends StatefulWidget {
 
   @override
   State<StatefulWidget> createState() {
-    return _MaterialControlsState();
+    return MaterialControlsState();
   }
 }
 
@@ -26,7 +27,7 @@ enum VerticalMode {
   Bright
 }
 
-class _MaterialControlsState extends State<I2MaterialControls> {
+class MaterialControlsState extends State<I2MaterialControls> {
   VideoPlayerValue _latestValue;
   double _latestVolume;
   bool _hideStuff = true;
@@ -54,6 +55,7 @@ class _MaterialControlsState extends State<I2MaterialControls> {
   double currentBright;
   double currentVolume;
   String valueText;
+  StreamSubscription _eventBusStreamSubscription;
 
   @override
   Widget build(BuildContext context) {
@@ -255,16 +257,22 @@ class _MaterialControlsState extends State<I2MaterialControls> {
 
   void _initState() async {
     FlutterVolume.disableUI();
+    _eventBusStreamSubscription = i2ControlEventBus.on<I2ControllerEvent>().listen((event){
+      if (event == I2ControllerEvent.ShowControl) {
+        _showControlWithoutTimer();
+      }
+    });
   }
 
   @override
   void dispose() {
+    _eventBusStreamSubscription.cancel();
+    Screen.resetAndroidBrightness();
     _dispose();
     super.dispose();
   }
 
   void _dispose() async {
-    Screen.resetAndroidBrightness();
     controller.removeListener(_updateState);
     _hideTimer?.cancel();
     _initTimer?.cancel();
@@ -598,6 +606,16 @@ class _MaterialControlsState extends State<I2MaterialControls> {
     });
   }
 
+  void _showControlWithoutTimer() {
+    _hideTimer?.cancel();
+    // 显示status bar
+    _showStatusBar();
+    setState(() {
+      _hideStuff = false;
+      _displayTapped = true;
+    });
+  }
+
   Future<Null> _initialize() async {
     controller.addListener(_updateState);
 

+ 3 - 0
pubspec.yaml

@@ -23,6 +23,9 @@ dependencies:
   sys_volume:
     git:
       url: https://github.com/hwh97/flutter_volume.git
+  event_bus:
+    git:
+      url: https://git.i2erp.cn/plugins/event_bus.git
 
   flutter:
     sdk: flutter