dispose method

void dispose({
  1. bool forceDispose = false,
})

Dispose BetterPlayerController. When forceDispose parameter is true, then autoDispose parameter will be overridden and controller will be disposed (if it wasn't disposed before).

Implementation

void dispose({bool forceDispose = false}) {
  if (!betterPlayerConfiguration.autoDispose && !forceDispose) {
    return;
  }
  if (!_disposed) {
    if (videoPlayerController != null) {
      pause();
      videoPlayerController!.removeListener(_onFullScreenStateChanged);
      videoPlayerController!.removeListener(_onVideoPlayerChanged);
      videoPlayerController!.dispose();
    }
    _eventListeners.clear();
    _nextVideoTimer?.cancel();
    _nextVideoTimeStreamController.close();
    _controlsVisibilityStreamController.close();
    _videoEventStreamSubscription?.cancel();
    _disposed = true;
    _controllerEventStreamController.close();

    ///Delete files async
    _tempFiles.forEach((file) => file.delete());
  }
}