【问题标题】:How to correctly catch up to the latest position in a live stream using video_player and Chewie?如何使用 video_player 和 Chewie 正确赶上实时流中的最新位置?
【发布时间】:2020-10-13 06:59:56
【问题描述】:

例如,当用户开始观看直播时,我将初始化播放器并从直播中的最新位置开始播放。如果用户随后暂停视频,他们将落后最新的流位置 x 秒。我想添加功能,让他们可以直接寻找最新的实时位置。

我目前的方法是简单地重新初始化流...

_videoPlayerController1 = VideoPlayerController.network('theUrl/index.m3u8');
_chewieController = ChewieController(
  videoPlayerController: _videoPlayerController1,
      autoPlay: true,
      isLive: true,
      autoInitialize: true,
    );

但是,由于这两个库非常强调在使用完它们后调用 dispose() 的必要性,我担心会在这里造成内存泄漏。这种方法好吗?

在调用上述代码之前,我确实尝试对它们都调用 dispose()...

_videoPlayerController1.dispose();
_chewieController.dispose();

虽然这导致了以下错误'A VideoPlayerController 在被处理后被使用。一旦你在 VideoPlayerController 上调用了 dispose(),它就不能再被使用了。'

我的方法是否会导致内存泄漏,是否有更好的方法来寻找最新的直播位置?

【问题讨论】:

    标签: flutter flutter-video-player


    【解决方案1】:

    我想通了。跳转到直播中最新位置的最简单方法是调用:

    _chewieController.seekTo(Duration(days: 30));
    

    在后台,Chewie 正在其 videoController 上调用 seekTo 方法,该方法记录如下:

    /// 如果 [moment] 超出视频的完整范围,它将自动 /// 并默默地夹紧。

    因此,如果您不知道流的最新位置,那么您可以传入一个比您期望的流的最新位置(本例中为 30 天)大得多的 Duration 值,并且 VideoController 将将其位置设置为其最新的已知位置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-12
      • 2013-05-07
      • 2012-03-05
      • 2021-08-14
      • 2011-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多