首页 > 解决方案 > Flutter video_player 声音有时与视频不同步

问题描述

我在使用 Flutter video_player 时遇到问题,有时视频会挂起并且声音与视频不同步。视频和声音之间有约 1 秒的延迟。这仅在播放某些视频时发生,大多数视频都很好。我检查了其中一个受影响的视频与其他视频的格式(mp4)相同,并且还从我的 S3 存储桶中下载了该视频,并确认它在这种情况下可以正常播放,所以我认为这一定是一个问题使用 video_player 插件。这是我加载视频控制器的代码。在音频和视频不同步的情况下,视频与此插件的行为是否会有所不同?

  void loadVideo() async {
    videoController =
        VideoPlayerController.network(videoLink);

    videoController.initialize().then((_) {
      if (!mounted) {
        // displays an error message if the video controller doesn't load
        videoError = true;
        setState(() {});
        return;
      }
      setState(() {});
    });

    videoController.addListener(_listenForError);
  }

  void playVideo() async {
    videoController.play();
  }

   Widget cameraWidget = Transform.scale(
      scale: videoController.value.aspectRatio / deviceRatio,
      child: AspectRatio(
        aspectRatio: videoController.value.aspectRatio,
        child: VideoPlayer(videoController),
      ),
    );

标签: flutterflutter-video-player

解决方案


推荐阅读