main.dart 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. import 'package:chewie/chewie.dart';
  2. import 'package:chewie/src/chewie_controller.dart';
  3. import 'package:flutter/cupertino.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:video_player/video_player.dart';
  6. void main() {
  7. runApp(
  8. ChewieDemo(),
  9. );
  10. }
  11. class ChewieDemo extends StatefulWidget {
  12. ChewieDemo({this.title = 'Chewie Demo'});
  13. final String title;
  14. @override
  15. State<StatefulWidget> createState() {
  16. return _ChewieDemoState();
  17. }
  18. }
  19. class _ChewieDemoState extends State<ChewieDemo> {
  20. TargetPlatform _platform;
  21. VideoPlayerController _videoPlayerController1;
  22. VideoPlayerController _videoPlayerController2;
  23. ChewieController _chewieController;
  24. @override
  25. void initState() {
  26. super.initState();
  27. _videoPlayerController1 = VideoPlayerController.network(
  28. 'https://flutter.github.io/assets-for-api-docs/assets/videos/butterfly.mp4');
  29. _videoPlayerController2 = VideoPlayerController.network(
  30. 'https://www.sample-videos.com/video123/mp4/480/big_buck_bunny_480p_20mb.mp4');
  31. _chewieController = ChewieController(
  32. videoPlayerController: _videoPlayerController1,
  33. aspectRatio: 3 / 2,
  34. autoPlay: true,
  35. looping: true,
  36. // Try playing around with some of these other options:
  37. // showControls: false,
  38. // materialProgressColors: ChewieProgressColors(
  39. // playedColor: Colors.red,
  40. // handleColor: Colors.blue,
  41. // backgroundColor: Colors.grey,
  42. // bufferedColor: Colors.lightGreen,
  43. // ),
  44. // placeholder: Container(
  45. // color: Colors.grey,
  46. // ),
  47. // autoInitialize: true,
  48. );
  49. }
  50. @override
  51. void dispose() {
  52. _videoPlayerController1.dispose();
  53. _videoPlayerController2.dispose();
  54. _chewieController.dispose();
  55. super.dispose();
  56. }
  57. @override
  58. Widget build(BuildContext context) {
  59. return MaterialApp(
  60. title: widget.title,
  61. theme: ThemeData.light().copyWith(
  62. platform: _platform ?? Theme.of(context).platform,
  63. ),
  64. home: Scaffold(
  65. appBar: AppBar(
  66. title: Text(widget.title),
  67. ),
  68. body: Column(
  69. children: <Widget>[
  70. Expanded(
  71. child: Center(
  72. child: Chewie(
  73. controller: _chewieController,
  74. ),
  75. ),
  76. ),
  77. FlatButton(
  78. onPressed: () {
  79. _chewieController.enterFullscreen();
  80. },
  81. child: Text('Fullscreen'),
  82. ),
  83. Row(
  84. children: <Widget>[
  85. Expanded(
  86. child: FlatButton(
  87. onPressed: () {
  88. setState(() {
  89. _chewieController.dispose();
  90. _videoPlayerController2.pause();
  91. _videoPlayerController2.seekTo(Duration(seconds: 0));
  92. _chewieController = ChewieController(
  93. videoPlayerController: _videoPlayerController1,
  94. aspectRatio: 3 / 2,
  95. autoPlay: true,
  96. looping: true,
  97. );
  98. });
  99. },
  100. child: Padding(
  101. child: Text("Video 1"),
  102. padding: EdgeInsets.symmetric(vertical: 16.0),
  103. ),
  104. ),
  105. ),
  106. Expanded(
  107. child: FlatButton(
  108. onPressed: () {
  109. setState(() {
  110. _chewieController.dispose();
  111. _videoPlayerController1.pause();
  112. _videoPlayerController1.seekTo(Duration(seconds: 0));
  113. _chewieController = ChewieController(
  114. videoPlayerController: _videoPlayerController2,
  115. aspectRatio: 3 / 2,
  116. autoPlay: true,
  117. looping: true,
  118. );
  119. });
  120. },
  121. child: Padding(
  122. padding: EdgeInsets.symmetric(vertical: 16.0),
  123. child: Text("Video 2"),
  124. ),
  125. ),
  126. )
  127. ],
  128. ),
  129. Row(
  130. children: <Widget>[
  131. Expanded(
  132. child: FlatButton(
  133. onPressed: () {
  134. setState(() {
  135. _platform = TargetPlatform.android;
  136. });
  137. },
  138. child: Padding(
  139. child: Text("Android controls"),
  140. padding: EdgeInsets.symmetric(vertical: 16.0),
  141. ),
  142. ),
  143. ),
  144. Expanded(
  145. child: FlatButton(
  146. onPressed: () {
  147. setState(() {
  148. _platform = TargetPlatform.iOS;
  149. });
  150. },
  151. child: Padding(
  152. padding: EdgeInsets.symmetric(vertical: 16.0),
  153. child: Text("iOS controls"),
  154. ),
  155. ),
  156. )
  157. ],
  158. )
  159. ],
  160. ),
  161. ),
  162. );
  163. }
  164. }