Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'dart:async';
- import 'package:video_player/video_player.dart';
- import '../textstyle.dart';
- class AssemblyPage extends StatefulWidget {
- @override
- _AssemblyPageState createState() => _AssemblyPageState();
- }
- class _AssemblyPageState extends State<AssemblyPage> {
- late VideoPlayerController _controller;
- late Future<void> _initializeVideoPlayerFuture;
- @override
- void initState() {
- super.initState();
- _controller = VideoPlayerController.asset('assets/videos/bahrain_Lec_ver.mp4');
- _initializeVideoPlayerFuture = _controller.initialize();
- _controller.setLooping(true);
- }
- @override
- void dispose() {
- _controller.dispose();
- super.dispose();
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- body: FutureBuilder(
- future: _initializeVideoPlayerFuture,
- builder: (context, snapshot) {
- if (snapshot.hasData) {
- return AspectRatio(
- aspectRatio: _controller.value.aspectRatio,
- child: VideoPlayer(_controller),
- );
- } else if (snapshot.hasError) {
- return MediumBlackText('Error: ${snapshot.error}');
- } else {
- return const Center(
- child: CircularProgressIndicator(),
- );
- }
- },
- ),
- floatingActionButton: FloatingActionButton(
- backgroundColor: Colors.red,
- onPressed: () {
- setState(() {
- if (_controller.value.isPlaying) {
- _controller.pause();
- } else {
- _controller.play();
- }
- });
- },
- child: Icon(
- _controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement