disposeNearByOldVideoControllers method

dynamic disposeNearByOldVideoControllers(
  1. int index
)

Implementation

disposeNearByOldVideoControllers(int index) async {
  loading.value = false;
  for (var i = index - loadLimit; i > 0; i--) {
    if (videoPlayerControllerList.asMap().containsKey(i)) {
      var oldVideoPlayerController = videoPlayerControllerList[i];
      VideoPlayerController videoPlayerControllerTmp =
          await videoControllerService.getControllerForVideo(
              videoList[i], isCaching);
      videoPlayerControllerList[i] = videoPlayerControllerTmp;
      alreadyListened.remove(i);
      await oldVideoPlayerController.dispose();
      refreshView();
    }
  }

  for (var i = index + loadLimit; i < videoPlayerControllerList.length; i++) {
    if (videoPlayerControllerList.asMap().containsKey(i)) {
      var oldVideoPlayerController = videoPlayerControllerList[i];
      VideoPlayerController videoPlayerControllerTmp =
          await videoControllerService.getControllerForVideo(
              videoList[i], isCaching);
      videoPlayerControllerList[i] = videoPlayerControllerTmp;
      alreadyListened.remove(i);
      await oldVideoPlayerController.dispose();
      refreshView();
    }
  }
}