0

For example, when the user starts watching the stream, I will initialize the player and that starts playing from the latest position in the live stream. If the user then pauses the video they will be x seconds behind the latest stream position. I want to add functionality to allow them to seek directly the latest live position.

My current approach is to simply reinitialize the stream...

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

However, as the two mentioned libraries heavily emphasize the need to call dispose() when finished with them I'm worried about creating memory leaks here. Is this approach okay?

I did try calling dispose() on them both before calling the above code...

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

Although that led to the following error 'A VideoPlayerController was used after being disposed. Once you have called dispose() on a VideoPlayerController, it can no longer be used.'

Does my approach lead to memory leaks and is there a better way to seek the latest live stream position?

Hamed
  • 5,867
  • 4
  • 32
  • 56
jaxfire
  • 156
  • 1
  • 7

2 Answers2

0

I figured it out. The simplest way jump to the latest position in a live stream is to call:

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

Under the hood, Chewie is calling the seekTo method on its videoController which is documented with the following:

/// If [moment] is outside of the video's full range it will be automatically /// and silently clamped.

So it seems that if you don't know the streams latest position then you can pass in a Duration value that is much larger than what you expect the stream's latest position to be (30 days in this example) and the VideoController will set it's position to its latest known position.

jaxfire
  • 156
  • 1
  • 7
0

Try the following code:

_videoPlayerController.seekTo(_videoPlayerController.value.duration);
My Car
  • 4,198
  • 5
  • 17
  • 50
Dilip
  • 1
  • 1
  • 1