mirrored_repositories/my-video-app
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
//import 'package:flutter_volume/flutter_volume.dart';
//import 'package:volume/volume.dart';



void main() => runApp(VideoPlayerApp());

class VideoPlayerApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Video Player Demo',
      home: VideoPlayerScreen(),
    );
  }
}

class VideoPlayerScreen extends StatefulWidget {
  
  //_MyAppState createState() => _MyAppState();
  VideoPlayerScreen({Key key}) : super(key: key);
  

  @override
  _VideoPlayerScreenState createState() => _VideoPlayerScreenState();
  
}

class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
  VideoPlayerController _controller;
  int _playbackTime = 0;
  Future<void> _initializeVideoPlayerFuture;

  @override
  void initState() {
    // Create and store the VideoPlayerController. The VideoPlayerController
    // offers several different constructors to play videos from assets, files,
    // or the internet.
    
    _controller = VideoPlayerController.network(
      'https://shirshadatta.github.io/My-portfolio/assets/cool_Trim.mp4',
    );
    

    // Initialize the controller and store the Future for later use.
    _initializeVideoPlayerFuture = _controller.initialize();

    // Use the controller to loop the video.
    _controller.setLooping(true);

    super.initState();
  }

  @override
  void dispose() {
    // Ensure disposing of the VideoPlayerController to free up resources.
    _controller.dispose();

    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
   
    return Scaffold(
      appBar: AppBar(
        title: Text('Brooklyn Nine-Nine',
          style: TextStyle(fontWeight: FontWeight.bold,
            color: Colors.black,
            fontSize: 22),
            ),
        backgroundColor: Colors.yellowAccent.shade400,
        leading: Icon(Icons.menu,
          color: Colors.black,
          size: 35,),
      ),
      // Use a FutureBuilder to display a loading spinner while waiting for the
      // VideoPlayerController to finish initializing.
      body: Container(
        alignment: Alignment.center,
        //border: Border.all(10),
        width: double.infinity,
        height: double.infinity,
        color: Colors.grey.shade300,
        margin: EdgeInsets.all(20),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          //alignment: Alignment.topCenter,
          children: <Widget>[
            
            Container(
              child: FutureBuilder(
                future: _initializeVideoPlayerFuture,
                builder: (context, snapshot) {
                  if (snapshot.connectionState == ConnectionState.done) {
                    // If the VideoPlayerController has finished initialization, use
                    // the data it provides to limit the aspect ratio of the video.
                    return AspectRatio(
                      aspectRatio: _controller.value.aspectRatio,
                      // Use the VideoPlayer widget to display the video.
                      child: VideoPlayer(_controller ),
                    );
                  } else {
                    // If the VideoPlayerController is still initializing, show a
                    // loading spinner.
                    return Center(child: CircularProgressIndicator());
                  }
                },
              ),
            ),
            /*Slider( 
              value: _playbackTime.toDouble(),
              max: _controller.value.duration.inSeconds.toDouble(),
              min: 0,
              onChanged: null,
            ),*/
          ],
        ),
      ),
      
      
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          // Wrap the play or pause in a call to `setState`. This ensures the
          // correct icon is shown.
          setState(() {
            // If the video is playing, pause it.
            if (_controller.value.isPlaying) {
              _controller.pause();
            } else {
              // If the video is paused, play it.
              _controller.play();
            }
          });
        },
        // Display the correct icon depending on the state of the player.
        child: Icon(
          _controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
        ),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
