title: Flutter (web) video_player Autoplay
body: <p>does anyone know what I need to do in order to get my videos to play automatically once my flutter website has loaded?</p>
  
  <p>The only thing I've managed so far is to get them to play/loop if I refresh the page manually.</p>
  
  <p>I'm sure it's something simple but after 3 months of not coding at all I'm a little rusty...</p>
  
  <p>At the moment I'm calling <code>_videoPlayerController.play()</code> inside the <code>FutureBuilder</code></p>
  
  <pre><code>class VideoWithChild extends StatefulWidget {
    final String videoSource;
    final FractionalOffset alignment;
    final TextAlign textAlign;
    final Widget child;
  
    const VideoWithChild(
        {Key key, this.videoSource, this.alignment, this.textAlign, this.child})
        : super(key: key);
  
    @override
    _VideoWithChildState createState() =&gt;
        _VideoWithChildState(videoSource, alignment, textAlign, child);
  }
  
  class _VideoWithChildState extends State&lt;VideoWithChild&gt; {
    final String videoSource;
    final TextAlign textAlign;
    final Widget child;
    final FractionalOffset alignment;
    VideoPlayerController _videoPlayerController;
    Future&lt;void&gt; _initializeVideoPlayerFuture;
    VoidCallback listener;
  
    _VideoWithChildState(
        this.videoSource, this.alignment, this.textAlign, this.child);
  
    @override
    void initState() {
      _videoPlayerController = VideoPlayerController.asset(videoSource);
      _initializeVideoPlayerFuture = _videoPlayerController.initialize();
      super.initState();
    }
  
    @override
    Widget build(BuildContext context) {
      print('build');
      return FutureBuilder(
        future: _initializeVideoPlayerFuture,
        builder: (context, snapshot) {
          if (snapshot.connectionState == ConnectionState.done &amp;&amp;
              _videoPlayerController.dataSource.isNotEmpty) {
                print('connection state');
            _videoPlayerController.play();
            _videoPlayerController.setLooping(true);
            return AspectRatio(
              aspectRatio: _videoPlayerController.value.aspectRatio,
              child: Stack(
                children: &lt;Widget&gt;[
                  VideoPlayer(_videoPlayerController),
                  LayoutBuilder(
                    builder: (context, constraints) {
                      return Align(alignment: alignment, child: child);
                    },
                  )
                ],
              ),
            );
          } else {
            return Padding(
              padding: const EdgeInsets.all(8.0),
              child: Center(
                  child: CircularProgressIndicator(
                valueColor: AlwaysStoppedAnimation&lt;Color&gt;(
                  Color(0xff49148c),
                ),
              )),
            );
          }
        },
      );
    }
  
    @override
    void dispose() {
      print('dispose');
      super.dispose();
      _videoPlayerController.dispose();
    }
  }
  </code></pre>