在颤振上播放视频

时间:2021-05-25 14:11:41

标签: flutter flutter-video-player

我正在尝试在我的 flutter 项目上播放视频,但它不起作用,发生错误。 似乎视频无法播放并出现播放错误和源错误。 下图中显示的完整错误。 这是我的代码:

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:

1 个答案:

答案 0 :(得分:0)

您是否在 pubspec.yaml 中添加了视频或视频文件夹?这样做并在此之后重新启动应用程序。 pubspec.yaml:

assets:
- assets/videos/

Dart 文件:

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