play video on flutter

Issue

I am trying to play a video on my flutter project but it doesn’t work ,an error occur.
It seems like the video couldn’t play and give me playback error and source error.
The full error shown in the picture below.
This is my code:

class _ChewieDemoState extends State<ChewieDemo> {
  TargetPlatform _platform;
  VideoPlayerController _videoPlayerController1;
 // VideoPlayerController _videoPlayerController2;
  ChewieController _chewieController;

  @override
  void initState() {
    super.initState();
    _videoPlayerController1 =  VideoPlayerController.asset('assets/numbervideo.mp4');
    //_videoPlayerController2 = VideoPlayerController.network(
     //   'https://youtu.be/68XVRhQQ49w');
    _chewieController = ChewieController(
      videoPlayerController: _videoPlayerController1,
      aspectRatio: 3 / 2,
      autoPlay: true,
      looping: true,
    );
  }

  @override
  void dispose() {
    _videoPlayerController1.dispose();
   // _videoPlayerController2.dispose();
    _chewieController.dispose();
    super.dispose();
  }

The error is:

Solution

Have you added video or video folder in your pubspec.yaml? Do it and restart the app after that.
Pubspec.yaml:

assets:
- assets/videos/

Dart file:

VideoPlayerController.asset('assets/videos/numbervideo.mp4');

Answered By – jestrabikr

Answer Checked By – David Goodson (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *