Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'package:video_player/video_player.dart';
- void main() => runApp(MyApp());
- class MyApp extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- title: 'Video Example',
- home: VideoExample(),
- );
- }
- }
- class VideoExample extends StatefulWidget {
- VideoState createState() => VideoState();
- }
- class VideoState extends State<VideoExample> {
- VideoPlayerController playerController;
- VoidCallback listener;
- @override
- void initState() {
- super.initState();
- listener = () {
- setState(() {});
- };
- }
- void createVideo() {
- if (playerController == null) {
- playerController =
- VideoPlayerController.asset('assets/videos/PilatesTestOverview.mp4')
- ..addListener(listener)
- ..setVolume(1.0)
- ..initialize();
- }
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text('Video Example'),
- ),
- body: Center(
- child: AspectRatio(
- aspectRatio: 16 / 9,
- child: Container(
- child: (playerController != null
- ? VideoPlayer(playerController)
- : Container()),
- ),
- ),
- ),
- floatingActionButton: FloatingActionButton(
- onPressed: () {
- createVideo();
- playerController.play();
- },
- child: Icon(Icons.play_arrow),
- ),
- );
- }
- }
Add Comment
Please, Sign In to add comment