|
|
@@ -0,0 +1,229 @@
|
|
|
+import 'package:chewie/chewie.dart';
|
|
|
+import 'package:chewie/src/chewie_player.dart';
|
|
|
+import 'package:flutter/cupertino.dart';
|
|
|
+import 'package:flutter/material.dart';
|
|
|
+import 'package:flutter/services.dart';
|
|
|
+import 'package:video_player/video_player.dart';
|
|
|
+import 'package:auto_orientation/auto_orientation.dart';
|
|
|
+
|
|
|
+void main() {
|
|
|
+ runApp(
|
|
|
+ ChewieDemo(),
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+class ChewieDemo extends StatefulWidget {
|
|
|
+ ChewieDemo({this.title = 'Chewie Demo'});
|
|
|
+
|
|
|
+ final String title;
|
|
|
+
|
|
|
+ @override
|
|
|
+ State<StatefulWidget> createState() {
|
|
|
+ return _ChewieDemoState();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+class _ChewieDemoState extends State<ChewieDemo> {
|
|
|
+ TargetPlatform _platform;
|
|
|
+ VideoPlayerController _videoPlayerController1;
|
|
|
+ VideoPlayerController _videoPlayerController2;
|
|
|
+ ChewieController _chewieController;
|
|
|
+
|
|
|
+ @override
|
|
|
+ void initState() {
|
|
|
+ super.initState();
|
|
|
+ _videoPlayerController1 = VideoPlayerController.network(
|
|
|
+ 'https://flutter.github.io/assets-for-api-docs/assets/videos/butterfly.mp4');
|
|
|
+ _videoPlayerController2 = VideoPlayerController.network(
|
|
|
+ 'https://www.sample-videos.com/video123/mp4/480/big_buck_bunny_480p_20mb.mp4');
|
|
|
+ _chewieController = ChewieController(
|
|
|
+ videoPlayerController: _videoPlayerController1,
|
|
|
+ aspectRatio: 3 / 2,
|
|
|
+ autoPlay: true,
|
|
|
+ looping: true,
|
|
|
+ routePageBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondAnimation, provider) {
|
|
|
+ return AnimatedBuilder(
|
|
|
+ animation: animation,
|
|
|
+ builder: (BuildContext context, Widget child) {
|
|
|
+ return VideoScaffold(
|
|
|
+ child: Scaffold(
|
|
|
+ resizeToAvoidBottomPadding: false,
|
|
|
+ body: Container(
|
|
|
+ alignment: Alignment.center,
|
|
|
+ color: Colors.black,
|
|
|
+ child: provider,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ },
|
|
|
+ );
|
|
|
+ }
|
|
|
+ // Try playing around with some of these other options:
|
|
|
+
|
|
|
+ // showControls: false,
|
|
|
+ // materialProgressColors: ChewieProgressColors(
|
|
|
+ // playedColor: Colors.red,
|
|
|
+ // handleColor: Colors.blue,
|
|
|
+ // backgroundColor: Colors.grey,
|
|
|
+ // bufferedColor: Colors.lightGreen,
|
|
|
+ // ),
|
|
|
+ // placeholder: Container(
|
|
|
+ // color: Colors.grey,
|
|
|
+ // ),
|
|
|
+ // autoInitialize: true,
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ @override
|
|
|
+ void dispose() {
|
|
|
+ _videoPlayerController1.dispose();
|
|
|
+ _videoPlayerController2.dispose();
|
|
|
+ _chewieController.dispose();
|
|
|
+ super.dispose();
|
|
|
+ }
|
|
|
+
|
|
|
+ @override
|
|
|
+ Widget build(BuildContext context) {
|
|
|
+ return MaterialApp(
|
|
|
+ title: widget.title,
|
|
|
+ theme: ThemeData.light().copyWith(
|
|
|
+ platform: _platform ?? Theme.of(context).platform,
|
|
|
+ ),
|
|
|
+ home: Scaffold(
|
|
|
+ appBar: AppBar(
|
|
|
+ title: Text(widget.title),
|
|
|
+ ),
|
|
|
+ body: Column(
|
|
|
+ children: <Widget>[
|
|
|
+ Expanded(
|
|
|
+ child: Center(
|
|
|
+ child: Chewie(
|
|
|
+ controller: _chewieController,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ FlatButton(
|
|
|
+ onPressed: () {
|
|
|
+ _chewieController.enterFullScreen();
|
|
|
+ },
|
|
|
+ child: Text('Fullscreen'),
|
|
|
+ ),
|
|
|
+ Row(
|
|
|
+ children: <Widget>[
|
|
|
+ Expanded(
|
|
|
+ child: FlatButton(
|
|
|
+ onPressed: () {
|
|
|
+ setState(() {
|
|
|
+ _chewieController.dispose();
|
|
|
+ _videoPlayerController2.pause();
|
|
|
+ _videoPlayerController2.seekTo(Duration(seconds: 0));
|
|
|
+ _chewieController = ChewieController(
|
|
|
+ videoPlayerController: _videoPlayerController1,
|
|
|
+ aspectRatio: 3 / 2,
|
|
|
+ autoPlay: true,
|
|
|
+ looping: true,
|
|
|
+ );
|
|
|
+ });
|
|
|
+ },
|
|
|
+ child: Padding(
|
|
|
+ child: Text("Video 1"),
|
|
|
+ padding: EdgeInsets.symmetric(vertical: 16.0),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ Expanded(
|
|
|
+ child: FlatButton(
|
|
|
+ onPressed: () {
|
|
|
+ setState(() {
|
|
|
+ _chewieController.dispose();
|
|
|
+ _videoPlayerController1.pause();
|
|
|
+ _videoPlayerController1.seekTo(Duration(seconds: 0));
|
|
|
+ _chewieController = ChewieController(
|
|
|
+ videoPlayerController: _videoPlayerController2,
|
|
|
+ aspectRatio: 3 / 2,
|
|
|
+ autoPlay: true,
|
|
|
+ looping: true,
|
|
|
+ );
|
|
|
+ });
|
|
|
+ },
|
|
|
+ child: Padding(
|
|
|
+ padding: EdgeInsets.symmetric(vertical: 16.0),
|
|
|
+ child: Text("Video 2"),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ )
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ Row(
|
|
|
+ children: <Widget>[
|
|
|
+ Expanded(
|
|
|
+ child: FlatButton(
|
|
|
+ onPressed: () {
|
|
|
+ setState(() {
|
|
|
+ _platform = TargetPlatform.android;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ child: Padding(
|
|
|
+ child: Text("Android controls"),
|
|
|
+ padding: EdgeInsets.symmetric(vertical: 16.0),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ Expanded(
|
|
|
+ child: FlatButton(
|
|
|
+ onPressed: () {
|
|
|
+ setState(() {
|
|
|
+ _platform = TargetPlatform.iOS;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ child: Padding(
|
|
|
+ padding: EdgeInsets.symmetric(vertical: 16.0),
|
|
|
+ child: Text("iOS controls"),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ )
|
|
|
+ ],
|
|
|
+ )
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+class VideoScaffold extends StatefulWidget {
|
|
|
+ final Widget child;
|
|
|
+
|
|
|
+ const VideoScaffold({Key key, this.child}) : super(key: key);
|
|
|
+
|
|
|
+ @override
|
|
|
+ State<StatefulWidget> createState() => _VideoScaffoldState();
|
|
|
+}
|
|
|
+
|
|
|
+class _VideoScaffoldState extends State<VideoScaffold> {
|
|
|
+
|
|
|
+ @override
|
|
|
+ void initState() {
|
|
|
+ SystemChrome.setPreferredOrientations([
|
|
|
+ DeviceOrientation.landscapeRight,
|
|
|
+ DeviceOrientation.landscapeLeft,
|
|
|
+ ]);
|
|
|
+ AutoOrientation.landscapeMode();
|
|
|
+ super.initState();
|
|
|
+ }
|
|
|
+
|
|
|
+ @override
|
|
|
+ dispose(){
|
|
|
+ SystemChrome.setPreferredOrientations([
|
|
|
+ DeviceOrientation.portraitUp,
|
|
|
+ DeviceOrientation.portraitDown,
|
|
|
+ ]);
|
|
|
+ AutoOrientation.portraitMode();
|
|
|
+ super.dispose();
|
|
|
+ }
|
|
|
+
|
|
|
+ @override
|
|
|
+ Widget build(BuildContext context) {
|
|
|
+ return widget.child;
|
|
|
+ }
|
|
|
+}
|