Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: using custom cache manager for caching #19

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/cached_video_player_plus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}');
Expand Down
22 changes: 22 additions & 0 deletions lib/src/video_cache_manager.dart
Original file line number Diff line number Diff line change
@@ -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));
}
Loading