Advertisement
Justsanesi

Video player

May 11th, 2022
1,579
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.81 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'dart:async';
  3. import 'package:video_player/video_player.dart';
  4. import '../textstyle.dart';
  5.  
  6.  
  7. class AssemblyPage extends StatefulWidget {
  8.   @override
  9.   _AssemblyPageState createState() => _AssemblyPageState();
  10. }
  11.  
  12. class _AssemblyPageState extends State<AssemblyPage> {
  13.   late VideoPlayerController _controller;
  14.   late Future<void> _initializeVideoPlayerFuture;
  15.  
  16.   @override
  17.   void initState() {
  18.     super.initState();
  19.     _controller = VideoPlayerController.asset('assets/videos/bahrain_Lec_ver.mp4');
  20.     _initializeVideoPlayerFuture = _controller.initialize();
  21.     _controller.setLooping(true);
  22.   }
  23.  
  24.   @override
  25.   void dispose() {
  26.     _controller.dispose();
  27.     super.dispose();
  28.   }
  29.  
  30.   @override
  31.   Widget build(BuildContext context) {
  32.     return Scaffold(
  33.       body: FutureBuilder(
  34.         future: _initializeVideoPlayerFuture,
  35.         builder: (context, snapshot) {
  36.           if (snapshot.hasData) {
  37.             return AspectRatio(
  38.               aspectRatio: _controller.value.aspectRatio,
  39.               child: VideoPlayer(_controller),
  40.             );
  41.           } else if (snapshot.hasError) {
  42.             return MediumBlackText('Error: ${snapshot.error}');
  43.           } else {
  44.             return const Center(
  45.               child: CircularProgressIndicator(),
  46.             );
  47.           }
  48.         },
  49.       ),
  50.       floatingActionButton: FloatingActionButton(
  51.         backgroundColor: Colors.red,
  52.         onPressed: () {
  53.           setState(() {
  54.             if (_controller.value.isPlaying) {
  55.               _controller.pause();
  56.             } else {
  57.               _controller.play();
  58.             }
  59.           });
  60.         },
  61.         child: Icon(
  62.           _controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
  63.         ),
  64.       ),
  65.     );
  66.   }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement