I'm using video_player to display video from assets folder but the video doesn't display. this is my code :
final controller = VideoPlayerController.asset('assets/camion.mp4');
Positioned(
top: MediaQuery.of(context).size.height * 0.4,
left: MediaQuery.of(context).size.width * 0.3,
child: Container(
width: 200,
height: 200,
child: VideoPlayer(controller),
),
),
And I'm sure that the video exists in assets folder
Did you add the video_player dependency in the pubspec.yaml?
dependencies:
flutter:
sdk: flutter
video_player: ^2.2.18
If you have in your assets folder also a folder for videos, you need to index the folder on pubspec.yaml file like below:
assets:
- assets/videos/
Import the package in your script:
import 'package:video_player/video_player.dart';
Initialize your video player:
late VideoPlayerController controller;
controller = VideoPlayerController.asset('assets/videos/video.mp4');
controller.initialize().then((value){
setState(() {});
});