main.dart 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 _videoPlayerController;
  22. ChewieController _chewieController;
  23. @override
  24. void initState() {
  25. super.initState();
  26. _videoPlayerController = VideoPlayerController.network(
  27. 'https://flutter.github.io/assets-for-api-docs/assets/videos/butterfly.mp4',
  28. );
  29. _chewieController = ChewieController(
  30. _videoPlayerController, aspectRatio: 3 / 2,
  31. autoPlay: true,
  32. looping: true,
  33. // Try playing around with some of these other options:
  34. // showControls: false,
  35. // materialProgressColors: ChewieProgressColors(
  36. // playedColor: Colors.red,
  37. // handleColor: Colors.blue,
  38. // backgroundColor: Colors.grey,
  39. // bufferedColor: Colors.lightGreen,
  40. // ),
  41. // placeholder: Container(
  42. // color: Colors.grey,
  43. // ),
  44. // autoInitialize: true,
  45. );
  46. }
  47. @override
  48. Widget build(BuildContext context) {
  49. return MaterialApp(
  50. title: widget.title,
  51. theme: ThemeData.light().copyWith(
  52. platform: _platform ?? Theme.of(context).platform,
  53. ),
  54. home: Scaffold(
  55. appBar: AppBar(
  56. title: Text(widget.title),
  57. ),
  58. body: Column(
  59. children: <Widget>[
  60. Expanded(
  61. child: Center(
  62. child: Chewie(
  63. controller: _chewieController,
  64. ),
  65. ),
  66. ),
  67. FlatButton(
  68. onPressed: () {
  69. _chewieController.enterFullscreen();
  70. },
  71. child: Text('Fullscreen'),
  72. ),
  73. Row(
  74. children: <Widget>[
  75. Expanded(
  76. child: FlatButton(
  77. onPressed: () {
  78. setState(() {
  79. _chewieController.videoPlayerController =
  80. VideoPlayerController.network(
  81. 'https://flutter.github.io/assets-for-api-docs/assets/videos/butterfly.mp4',
  82. );
  83. });
  84. },
  85. child: Padding(
  86. child: Text("Video 1"),
  87. padding: EdgeInsets.symmetric(vertical: 16.0),
  88. ),
  89. ),
  90. ),
  91. Expanded(
  92. child: FlatButton(
  93. onPressed: () {
  94. setState(() {
  95. _chewieController.videoPlayerController =
  96. VideoPlayerController.network(
  97. 'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4',
  98. // 'https://www.sample-videos.com/video123/mp4/480/big_buck_bunny_480p_20mb.mp4',
  99. );
  100. });
  101. },
  102. child: Padding(
  103. padding: EdgeInsets.symmetric(vertical: 16.0),
  104. child: Text("Video 2"),
  105. ),
  106. ),
  107. )
  108. ],
  109. ),
  110. Row(
  111. children: <Widget>[
  112. Expanded(
  113. child: FlatButton(
  114. onPressed: () {
  115. setState(() {
  116. _platform = TargetPlatform.android;
  117. });
  118. },
  119. child: Padding(
  120. child: Text("Android controls"),
  121. padding: EdgeInsets.symmetric(vertical: 16.0),
  122. ),
  123. ),
  124. ),
  125. Expanded(
  126. child: FlatButton(
  127. onPressed: () {
  128. setState(() {
  129. _platform = TargetPlatform.iOS;
  130. });
  131. },
  132. child: Padding(
  133. padding: EdgeInsets.symmetric(vertical: 16.0),
  134. child: Text("iOS controls"),
  135. ),
  136. ),
  137. )
  138. ],
  139. )
  140. ],
  141. ),
  142. ),
  143. );
  144. }
  145. }