Guest User

Untitled

a guest
Dec 10th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:video_player/video_player.dart';
  3.  
  4. void main() => runApp(MyApp());
  5.  
  6. class MyApp extends StatelessWidget {
  7.  
  8. @override
  9. Widget build(BuildContext context) {
  10.  
  11. return MaterialApp(
  12. title: 'Video Example',
  13. home: VideoExample(),
  14. );
  15. }
  16. }
  17.  
  18. class VideoExample extends StatefulWidget {
  19.  
  20. VideoState createState() => VideoState();
  21. }
  22.  
  23. class VideoState extends State<VideoExample> {
  24. VideoPlayerController playerController;
  25. VoidCallback listener;
  26.  
  27. @override
  28. void initState() {
  29. super.initState();
  30. listener = () {
  31. setState(() {});
  32. };
  33. }
  34.  
  35. void createVideo() {
  36. if (playerController == null) {
  37. playerController =
  38. VideoPlayerController.asset('assets/videos/PilatesTestOverview.mp4')
  39. ..addListener(listener)
  40. ..setVolume(1.0)
  41. ..initialize();
  42. }
  43. }
  44.  
  45. @override
  46. Widget build(BuildContext context) {
  47. return Scaffold(
  48. appBar: AppBar(
  49. title: Text('Video Example'),
  50. ),
  51. body: Center(
  52. child: AspectRatio(
  53. aspectRatio: 16 / 9,
  54. child: Container(
  55. child: (playerController != null
  56. ? VideoPlayer(playerController)
  57. : Container()),
  58. ),
  59. ),
  60. ),
  61. floatingActionButton: FloatingActionButton(
  62. onPressed: () {
  63. createVideo();
  64. playerController.play();
  65. },
  66. child: Icon(Icons.play_arrow),
  67. ),
  68. );
  69. }
  70. }
Add Comment
Please, Sign In to add comment