Browse Source

Update full screen impl.

Caijinglong 6 years ago
parent
commit
55ddf0f7d1
3 changed files with 69 additions and 16 deletions
  1. 20 11
      README.md
  2. 14 1
      lib/src/widget/controller_widget_builder.dart
  3. 35 4
      lib/src/widget/full_screen.part.dart

+ 20 - 11
README.md

@@ -438,17 +438,26 @@ IJKPlayer(
 
 这个类提供了一些属性进行自定义, 除`controller`外所有属性均为可选:
 
-|               name                |            type            |      default      |                      desc                       |
-| :-------------------------------: | :------------------------: | :---------------: | :---------------------------------------------: |
-|           doubleTapPlay           |            bool            |       false       |                  双击播放暂停                   |
-|          verticalGesture          |            bool            |       true        |                    纵向手势                     |
-|         horizontalGesture         |            bool            |       true        |                    横向手势                     |
-|            volumeType             |         VolumeType         | VolumeType.system |        纵向手势改变的声音类型(系统,媒体)        |
-|        playWillPauseOther         |            bool            |       true        |            播放当前是否暂停其他媒体             |
-|      currentFullScreenState       |            bool            |       false       | **如果你是自定义全屏界面, 这个必须设置为 true** |
-|       showFullScreenButton        |            bool            |       true        |                是否显示全屏按钮                 |
-| fullscreenControllerWidgetBuilder | IJKControllerWidgetBuilder |                   |              可以自定义全屏的界面               |
-|          fullScreenType           |       FullScreenType       |                   |     全屏的类型(旋转屏幕,或是使用 RotateBox)     |
+|               name                |            type            |      default      |                              desc                              |
+| :-------------------------------: | :------------------------: | :---------------: | :------------------------------------------------------------: |
+|           doubleTapPlay           |            bool            |       false       |                          双击播放暂停                          |
+|          verticalGesture          |            bool            |       true        |                            纵向手势                            |
+|         horizontalGesture         |            bool            |       true        |                            横向手势                            |
+|            volumeType             |         VolumeType         | VolumeType.system |               纵向手势改变的声音类型(系统,媒体)                |
+|        playWillPauseOther         |            bool            |       true        |                    播放当前是否暂停其他媒体                    |
+|      currentFullScreenState       |            bool            |       false       |        **如果你是自定义全屏界面, 这个必须设置为 true**         |
+|       showFullScreenButton        |            bool            |       true        |                        是否显示全屏按钮                        |
+| fullscreenControllerWidgetBuilder | IJKControllerWidgetBuilder |                   |                      可以自定义全屏的界面                      |
+|          fullScreenType           |       FullScreenType       |                   |            全屏的类型(旋转屏幕,或是使用 RotateBox)             |
+|     hideSystemBarOnFullScreen     |            bool            |       true        |         进入全屏时,是否自动隐藏状态栏(请看额外说明 1)          |
+|           onFullScreen            |    void Function(bool)     |       null        | 全屏状态改变时的回调, 参数为 true 是全屏状态, false 为普通状态 |
+
+**额外说明 1**: ios 需要向 Info.plist 添加一条属性
+
+```xml
+<key>UIViewControllerBasedStatusBarAppearance</key>
+<true/>
+```
 
 ### 自定义纹理界面
 

+ 14 - 1
lib/src/widget/controller_widget_builder.dart

@@ -51,11 +51,18 @@ class DefaultIJKControllerWidget extends StatefulWidget {
   /// The current full-screen button style should not be changed by users.
   final bool currentFullScreenState;
 
+  /// Build widget for full screen.
   final IJKControllerWidgetBuilder fullscreenControllerWidgetBuilder;
 
   /// See [FullScreenType]
   final FullScreenType fullScreenType;
 
+  /// Whether to automatically hide the status bar when it is full screen.
+  final bool hideSystemBarOnFullScreen;
+
+  /// Callback in full screen, full screen when enter true, false to exit full screen.
+  final void Function(bool enter) onFullScreen;
+
   /// The UI of the controller.
   const DefaultIJKControllerWidget({
     Key key,
@@ -69,6 +76,8 @@ class DefaultIJKControllerWidget extends StatefulWidget {
     this.showFullScreenButton = true,
     this.fullscreenControllerWidgetBuilder,
     this.fullScreenType = FullScreenType.rotateBox,
+    this.hideSystemBarOnFullScreen = true,
+    this.onFullScreen,
   }) : super(key: key);
 
   @override
@@ -229,6 +238,8 @@ class _DefaultIJKControllerWidgetState extends State<DefaultIJKControllerWidget>
             controller,
             fullscreenControllerWidgetBuilder: fullscreenBuilder,
             fullScreenType: widget.fullScreenType,
+            hideSystemBar: widget.hideSystemBarOnFullScreen,
+            onFullscreen: widget.onFullScreen,
           );
         }
       },
@@ -283,7 +294,9 @@ class _DefaultIJKControllerWidgetState extends State<DefaultIJKControllerWidget>
           ),
         );
 
-        if (this.widget.fullScreenType == FullScreenType.rotateBox && this.widget.currentFullScreenState && _overlayTurns != 0) {
+        if (this.widget.fullScreenType == FullScreenType.rotateBox &&
+            this.widget.currentFullScreenState &&
+            _overlayTurns != 0) {
           w = RotatedBox(
             child: w,
             quarterTurns: _overlayTurns,

+ 35 - 4
lib/src/widget/full_screen.part.dart

@@ -10,12 +10,16 @@ showFullScreenIJKPlayer(
   IjkMediaController controller, {
   IJKControllerWidgetBuilder fullscreenControllerWidgetBuilder,
   FullScreenType fullScreenType = FullScreenType.rotateBox,
+  bool hideSystemBar = true,
+  void Function(bool enter) onFullscreen,
 }) async {
   if (fullScreenType == FullScreenType.rotateBox) {
     _showFullScreenWithRotateBox(
       context,
       controller,
       fullscreenControllerWidgetBuilder: fullscreenControllerWidgetBuilder,
+      hideSystemBar: hideSystemBar,
+      onFullscreen: onFullscreen,
     );
     return;
   }
@@ -24,13 +28,21 @@ showFullScreenIJKPlayer(
     context,
     controller,
     fullscreenControllerWidgetBuilder,
+    hideSystemBar: hideSystemBar,
+    onFullscreen: onFullscreen,
   );
 }
 
 _showFullScreenWithRotateScreen(
-    BuildContext context,
-    IjkMediaController controller,
-    IJKControllerWidgetBuilder fullscreenControllerWidgetBuilder) async {
+  BuildContext context,
+  IjkMediaController controller,
+  IJKControllerWidgetBuilder fullscreenControllerWidgetBuilder, {
+  bool hideSystemBar,
+  void Function(bool enter) onFullscreen,
+}) async {
+  if (hideSystemBar) {
+    IjkManager.showStatusBar(false);
+  }
   Navigator.push(
     context,
     FullScreenRoute(
@@ -45,8 +57,14 @@ _showFullScreenWithRotateScreen(
   ).then((_) {
     IjkManager.unlockOrientation();
     IjkManager.setCurrentOrientation(DeviceOrientation.portraitUp);
+    if (hideSystemBar) {
+      IjkManager.showStatusBar(true);
+    }
+    onFullscreen?.call(false);
   });
 
+  onFullscreen?.call(true);
+
   var info = await controller.getVideoInfo();
 
   Axis axis;
@@ -78,6 +96,8 @@ _showFullScreenWithRotateBox(
   BuildContext context,
   IjkMediaController controller, {
   IJKControllerWidgetBuilder fullscreenControllerWidgetBuilder,
+  bool hideSystemBar,
+  void Function(bool enter) onFullscreen,
 }) async {
   var info = await controller.getVideoInfo();
 
@@ -99,6 +119,10 @@ _showFullScreenWithRotateBox(
     }
   }
 
+  if (hideSystemBar) {
+    IjkManager.showStatusBar(false);
+  }
+
   Navigator.push(
     context,
     FullScreenRoute(
@@ -136,7 +160,14 @@ _showFullScreenWithRotateBox(
         );
       },
     ),
-  );
+  ).then((data) {
+    if (hideSystemBar) {
+      IjkManager.showStatusBar(true);
+    }
+    onFullscreen?.call(false);
+  });
+
+  onFullscreen?.call(true);
 }
 
 Widget _buildFullScreenMediaController(