main.dart 4.3 KB

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