Просмотр исходного кода

resolves video_player version & adds support for starting video on fullscreen (#56)

* adds support for fullscreen video

* fixes version

* adds support for starting the videos in full screen mode as soon as play is pressed

* Update pubspec.yaml

* Update pubspec.yaml
Miguel Ruivo 7 лет назад
Родитель
Сommit
3a6c3e97af
2 измененных файлов с 24 добавлено и 7 удалено
  1. 23 6
      lib/src/chewie_player.dart
  2. 1 1
      pubspec.yaml

+ 23 - 6
lib/src/chewie_player.dart

@@ -48,6 +48,9 @@ class Chewie extends StatefulWidget {
   /// or played.
   final Widget placeholder;
 
+  /// Defines if the player will start in fullscreen when play is pressed
+  final bool fullScreenByDefault;
+
   Chewie(
     this.controller, {
     Key key,
@@ -56,12 +59,12 @@ class Chewie extends StatefulWidget {
     this.autoPlay = false,
     this.startAt,
     this.looping = false,
+    this.fullScreenByDefault = false,
     this.cupertinoProgressColors,
     this.materialProgressColors,
     this.placeholder,
     this.showControls = true,
-  })  : assert(controller != null,
-            'You must provide a controller to play a video'),
+  })  : assert(controller != null, 'You must provide a controller to play a video'),
         super(key: key);
 
   @override
@@ -72,6 +75,7 @@ class Chewie extends StatefulWidget {
 
 class _ChewiePlayerState extends State<Chewie> {
   VideoPlayerController _controller;
+  bool _isFullScreen = false;
 
   @override
   Widget build(BuildContext context) {
@@ -94,8 +98,7 @@ class _ChewiePlayerState extends State<Chewie> {
     _initialize();
   }
 
-  Widget _buildFullScreenVideo(
-      BuildContext context, Animation<double> animation) {
+  Widget _buildFullScreenVideo(BuildContext context, Animation<double> animation) {
     return new Scaffold(
       resizeToAvoidBottomPadding: false,
       body: new Container(
@@ -103,8 +106,7 @@ class _ChewiePlayerState extends State<Chewie> {
         color: Colors.black,
         child: new PlayerWithControls(
           controller: _controller,
-          onExpandCollapse: () =>
-              new Future<dynamic>.value(Navigator.of(context).pop()),
+          onExpandCollapse: () => new Future<dynamic>.value(Navigator.of(context).pop()),
           aspectRatio: widget.aspectRatio ?? _calculateAspectRatio(context),
           fullScreen: true,
           cupertinoProgressColors: widget.cupertinoProgressColors,
@@ -135,12 +137,26 @@ class _ChewiePlayerState extends State<Chewie> {
     }
 
     if (widget.autoPlay) {
+      if (widget.fullScreenByDefault) {
+        _isFullScreen = true;
+        await _pushFullScreenWidget(context);
+      }
+
       await _controller.play();
     }
 
     if (widget.startAt != null) {
       await _controller.seekTo(widget.startAt);
     }
+
+    if (widget.fullScreenByDefault) {
+      widget.controller.addListener(() async {
+        if (await widget.controller.value.isPlaying && !_isFullScreen) {
+          _isFullScreen = true;
+          await _pushFullScreenWidget(context);
+        }
+      });
+    }
   }
 
   @override
@@ -150,6 +166,7 @@ class _ChewiePlayerState extends State<Chewie> {
     if (widget.controller.dataSource != _controller.dataSource) {
       _controller.dispose();
       _controller = widget.controller;
+      _isFullScreen = false;
       _initialize();
     }
   }

+ 1 - 1
pubspec.yaml

@@ -9,7 +9,7 @@ environment:
 
 dependencies:
   open_iconic_flutter: ">=0.3.0 <0.4.0"
-  video_player: ">=0.6.0 <0.7.0"
+  video_player: ">= 0.6.0 <0.6.4" # video_player should stay at 0.6.4 due to a bug that prevents video rendering with chewie
   flutter:
     sdk: flutter