From f895a3e5975ff31d466b2b5b66d43580e03af1d3 Mon Sep 17 00:00:00 2001 From: OutdatedGuy Date: Thu, 11 Apr 2024 04:42:11 +0530 Subject: [PATCH] feat!: using custom cache manager for caching --- lib/cached_video_player_plus.dart | 3 ++- lib/src/video_cache_manager.dart | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 lib/src/video_cache_manager.dart diff --git a/lib/cached_video_player_plus.dart b/lib/cached_video_player_plus.dart index cb40c76..9d7ded9 100644 --- a/lib/cached_video_player_plus.dart +++ b/lib/cached_video_player_plus.dart @@ -20,6 +20,7 @@ import 'package:get_storage/get_storage.dart'; import 'package:video_player_platform_interface/video_player_platform_interface.dart'; import 'src/closed_caption_file.dart'; +import 'src/video_cache_manager.dart'; export 'package:video_player_platform_interface/video_player_platform_interface.dart' show DataSourceType, DurationRange, VideoFormat, VideoPlayerOptions; @@ -432,7 +433,7 @@ class CachedVideoPlayerPlusController bool isCacheAvailable = false; if (dataSourceType == DataSourceType.network && _isCachingSupported) { - final cacheManager = DefaultCacheManager(); + final cacheManager = VideoCacheManager(); FileInfo? cachedFile = await cacheManager.getFileFromCache(dataSource); debugPrint('Cached video of [$dataSource] is: ${cachedFile?.file.path}'); diff --git a/lib/src/video_cache_manager.dart b/lib/src/video_cache_manager.dart new file mode 100644 index 0000000..fc22f7e --- /dev/null +++ b/lib/src/video_cache_manager.dart @@ -0,0 +1,22 @@ +// Third Party Packages +import 'package:flutter_cache_manager/flutter_cache_manager.dart'; + +/// The [VideoCacheManager] is a specialized [CacheManager] for videos cached +/// using the [cached_video_player_plus] package. +/// +/// [cached_video_player_plus]: https://pub.dev/packages/cached_video_player_plus +class VideoCacheManager extends CacheManager with ImageCacheManager { + /// The key used to store the [VideoCacheManager] in the [CacheManager]. + static const key = 'libCachedVideoPlayerPlusData'; + + /// The singleton instance of the [VideoCacheManager]. + static final VideoCacheManager _instance = VideoCacheManager._(); + + /// Returns the singleton instance of the [VideoCacheManager]. + factory VideoCacheManager() { + return _instance; + } + + /// Creates a new instance of the [VideoCacheManager]. + VideoCacheManager._() : super(Config(key)); +}