소스 검색

Take a controller instead of a String

Brian Egan 8 년 전
부모
커밋
60ffa7fb38
4개의 변경된 파일30개의 추가작업 그리고 14개의 파일을 삭제
  1. 4 0
      CHANGELOG.md
  2. 4 2
      README.md
  3. 12 1
      example/lib/main.dart
  4. 10 11
      lib/src/chewie_player.dart

+ 4 - 0
CHANGELOG.md

@@ -1,5 +1,9 @@
 # Changelog
 
+## 0.2.0
+
+  * Take a `controller` instead of a `String uri`. Allows for better control of playback outside the player if need be.
+
 ## 0.1.1
 
   * Fix images in docs for pub 

+ 4 - 2
README.md

@@ -14,7 +14,7 @@ In your `pubspec.yaml` file within your Flutter Project:
 
 ```yaml
 dependencies:
-  chewie: ^0.1.0
+  chewie: ^0.2.0
 ```
 
 ## Use it
@@ -23,7 +23,9 @@ dependencies:
 import 'package:chewie/chewie.dart';
 
 final playerWidget = new Chewie(
-  'https://flutter.github.io/assets-for-api-docs/videos/butterfly.mp4',
+  new VideoPlayerController(
+    'https://flutter.github.io/assets-for-api-docs/videos/butterfly.mp4'
+  ),
   aspectRatio: 3 / 2,
   autoPlay: true,
   looping: true,

+ 12 - 1
example/lib/main.dart

@@ -1,6 +1,7 @@
 import 'package:chewie/chewie.dart';
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/material.dart';
+import 'package:video_player/video_player.dart';
 
 void main() => runApp(new ChewieDemo());
 
@@ -17,6 +18,7 @@ class ChewieDemo extends StatefulWidget {
 
 class _ChewieDemoState extends State<ChewieDemo> {
   TargetPlatform _platform;
+  VideoPlayerController controller;
 
   @override
   Widget build(BuildContext context) {
@@ -34,7 +36,7 @@ class _ChewieDemoState extends State<ChewieDemo> {
             new Expanded(
               child: new Center(
                 child: new Chewie(
-                  'https://flutter.github.io/assets-for-api-docs/videos/butterfly.mp4',
+                  controller,
                   aspectRatio: 3 / 2,
                   autoPlay: true,
                   looping: true,
@@ -86,4 +88,13 @@ class _ChewieDemoState extends State<ChewieDemo> {
       ),
     );
   }
+
+  @override
+  void initState() {
+    controller = new VideoPlayerController(
+      'https://flutter.github.io/assets-for-api-docs/videos/butterfly.mp4',
+    );
+
+    super.initState();
+  }
 }

+ 10 - 11
lib/src/chewie_player.dart

@@ -10,6 +10,9 @@ import 'package:video_player/video_player.dart';
 /// `video_player` is pretty low level. Chewie wraps it in a friendly skin to
 /// make it easy to use!
 class Chewie extends StatefulWidget {
+  /// The Controller for the Video you want to play
+  final VideoPlayerController controller;
+
   /// Initialize the Video on Startup. This will prep the video for playback.
   final bool autoInitialize;
 
@@ -34,11 +37,8 @@ class Chewie extends StatefulWidget {
   /// or played.
   final Widget placeholder;
 
-  // THe internal controller created from the URI.
-  final VideoPlayerController _controller;
-
   Chewie(
-    String uri, {
+    this.controller, {
     Key key,
     this.aspectRatio,
     this.autoInitialize = false,
@@ -47,8 +47,7 @@ class Chewie extends StatefulWidget {
     this.progressColors,
     this.placeholder,
   })
-      : assert(uri != null, 'You must provide a URI to a video'),
-        this._controller = new VideoPlayerController(uri),
+      : assert(controller != null, 'You must provide a controller to play a video'),
         super(key: key);
 
   @override
@@ -61,7 +60,7 @@ class _ChewiePlayerState extends State<Chewie> {
   @override
   Widget build(BuildContext context) {
     return new PlayerWithControls(
-      controller: widget._controller,
+      controller: widget.controller,
       onExpandCollapse: () {
         return _pushFullScreenWidget(context);
       },
@@ -85,7 +84,7 @@ class _ChewiePlayerState extends State<Chewie> {
       body: new Container(
         color: Colors.black,
         child: new PlayerWithControls(
-          controller: widget._controller,
+          controller: widget.controller,
           onExpandCollapse: () => new Future.value(Navigator.of(context).pop()),
           aspectRatio: widget.aspectRatio,
           fullScreen: true,
@@ -108,14 +107,14 @@ class _ChewiePlayerState extends State<Chewie> {
   }
 
   Future _initialize() async {
-    await widget._controller.setLooping(widget.looping);
+    await widget.controller.setLooping(widget.looping);
 
     if (widget.autoInitialize || widget.autoPlay) {
-      await widget._controller.initialize();
+      await widget.controller.initialize();
     }
 
     if (widget.autoPlay) {
-      await widget._controller.play();
+      await widget.controller.play();
     }
   }