main.dart 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. final String title;
  13. ChewieDemo({this.title = 'Chewie Demo'});
  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. _chewieController = ChewieController(
  91. videoPlayerController: _videoPlayerController1,
  92. aspectRatio: 3 / 2,
  93. autoPlay: true,
  94. looping: true,
  95. );
  96. });
  97. },
  98. child: Padding(
  99. child: Text("Video 1"),
  100. padding: EdgeInsets.symmetric(vertical: 16.0),
  101. ),
  102. ),
  103. ),
  104. Expanded(
  105. child: FlatButton(
  106. onPressed: () {
  107. setState(() {
  108. _chewieController.dispose();
  109. _chewieController = ChewieController(
  110. videoPlayerController: _videoPlayerController2,
  111. aspectRatio: 3 / 2,
  112. autoPlay: true,
  113. looping: true,
  114. );
  115. });
  116. },
  117. child: Padding(
  118. padding: EdgeInsets.symmetric(vertical: 16.0),
  119. child: Text("Video 2"),
  120. ),
  121. ),
  122. )
  123. ],
  124. ),
  125. Row(
  126. children: <Widget>[
  127. Expanded(
  128. child: FlatButton(
  129. onPressed: () {
  130. setState(() {
  131. _platform = TargetPlatform.android;
  132. });
  133. },
  134. child: Padding(
  135. child: Text("Android controls"),
  136. padding: EdgeInsets.symmetric(vertical: 16.0),
  137. ),
  138. ),
  139. ),
  140. Expanded(
  141. child: FlatButton(
  142. onPressed: () {
  143. setState(() {
  144. _platform = TargetPlatform.iOS;
  145. });
  146. },
  147. child: Padding(
  148. padding: EdgeInsets.symmetric(vertical: 16.0),
  149. child: Text("iOS controls"),
  150. ),
  151. ),
  152. )
  153. ],
  154. )
  155. ],
  156. ),
  157. ),
  158. );
  159. }
  160. }