title: How do you play a video outside of the video player class?
body: <p>Sorry if the question isn't that straight forward I'm just starting out. Every play video example I see through flutter examples uses a floating action button in the same class as the video player. I want to add a video player instance to my home screen and experiment with different ways to play the video (tapping on different elements, etc. I can't seem to gain access to the instance to access the controller. I'm not sure how to actually create a video player instance and then access the video controller from another place.</p>
  
  <pre><code>import 'dart:async';
  import 'package:flutter/material.dart';
  import 'package:video_player/video_player.dart';
  
  
  class VideoPlayerScreen extends StatefulWidget {
    VideoPlayerScreen({Key key}) : super(key: key);
    final VideoPlayerScreenState videoState = new VideoPlayerScreenState();
    @override
    VideoPlayerScreenState createState() =&gt; VideoPlayerScreenState();
  }
  
  class VideoPlayerScreenState extends State&lt;VideoPlayerScreen&gt; {
    VideoPlayerController controller;
    Future&lt;void&gt; 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://flutter.github.io/assets-for-api-docs/assets/videos/butterfly.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 you dispose the VideoPlayerController to free up resources
      controller.dispose();
  
      super.dispose();
    }
  
    @override
    Widget build(BuildContext context) {
      return Container(
        // Use a FutureBuilder to display a loading spinner while you wait for the
        // VideoPlayerController to finish initializing.
        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());
            }
          },
        ),
      );
    }
  }
  
  //this is the button I'm calling from the app.dart file
  
  Widget playPauseButton(VideoPlayerScreen videoPlayer){
  
    return IconButton(
      alignment: Alignment.center,
  
      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 (videoPlayer.videoState.controller.value.isPlaying) {
                videoPlayer.videoState.controller.pause();
              } else {
                // If the video is paused, play it
                videoPlayer.videoState.controller.play();
              }
            });
          },
        icon: Icon(videoPlayer.videoState.controller.value.isPlaying ? Icons.pause: Icons.play_arrow),
  
    );
  }
  </code></pre>