3

Is there any way to show the video player's controls by default? I'm able to show them if I right-click the video in a browser, so I'm assuming there must be a way to show by default..

enter image description here

Chris
  • 1,720
  • 16
  • 35

1 Answers1

5

I couldn't figure out a way to show the video_player controls by default, but instead have used this package and it works fine for Flutter-web: https://pub.dev/packages/chewie

I'm pretty sure you also need the default video_player package...

Here's an example:

import 'package:chewie/chewie.dart';
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';

class ChewieVideo extends StatefulWidget {
  // This will contain the URL/asset path which we want to play
  final VideoPlayerController videoPlayerController;
  final bool looping;

  ChewieVideo({
    @required this.videoPlayerController,
    this.looping,
    Key key,
  }) : super(key: key);

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

class _ChewieVideoState extends State<ChewieVideo> {
  ChewieController _chewieController;

  @override
  void initState() {
    super.initState();
    // Wrapper on top of the videoPlayerController

    _chewieController = ChewieController(
      videoPlayerController: widget.videoPlayerController,

      // Prepare the video to be played and display the first frame
      autoInitialize: true,
      allowFullScreen: false,
      aspectRatio: 16 / 9,
      looping: widget.looping,
      autoPlay: false,
      showControlsOnInitialize: false,
      // Errors can occur for example when trying to play a video
      // from a non-existent URL
      errorBuilder: (context, errorMessage) {
        return Center(
          child: Text(
            errorMessage,
            style: TextStyle(color: Colors.white),
          ),
        );
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: Chewie(
        controller: _chewieController,
      ),
    );
  }

  @override
  void dispose() {
    widget.videoPlayerController.dispose();
    _chewieController.dispose();
    super.dispose();
  }
}
Chris
  • 1,720
  • 16
  • 35