Skip to content
Merged
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
43 changes: 17 additions & 26 deletions lib/src/cached_video_player_plus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,7 @@ class CachedVideoPlayerPlus {
/// Returns a [Future] that completes when initialization is finished.
Future<void> initialize() async {
if (_isInitialized) {
if (kDebugMode) {
debugPrint('CachedVideoPlayerPlus is already initialized.');
}
_debugPrint('CachedVideoPlayerPlus is already initialized.');
return;
}

Expand All @@ -286,11 +284,7 @@ class CachedVideoPlayerPlus {
if (_shouldUseCache) {
FileInfo? cachedFile = await _cacheManager.getFileFromCache(_cacheKey);

if (kDebugMode) {
debugPrint(
'Cached video of [$dataSource] is: ${cachedFile?.file.path}',
);
}
_debugPrint('Cached video of [$dataSource] is: ${cachedFile?.file.path}');

if (cachedFile != null) {
final cachedElapsedMillis = await _storage.read(_cacheKey);
Expand All @@ -303,20 +297,16 @@ class CachedVideoPlayerPlus {
);
final difference = now.difference(cachedDate);

if (kDebugMode) {
debugPrint(
'Cache for [$dataSource] valid till: '
'${cachedDate.add(invalidateCacheIfOlderThan)}',
);
}
_debugPrint(
'Cache for [$dataSource] valid till: '
'${cachedDate.add(invalidateCacheIfOlderThan)}',
);

isCacheExpired = difference > invalidateCacheIfOlderThan;
}

if (isCacheExpired) {
if (kDebugMode) {
debugPrint('Cache of [$dataSource] expired. Removing...');
}
_debugPrint('Cache of [$dataSource] expired. Removing...');
_cacheManager.removeFile(_cacheKey);
cachedFile = null;
}
Expand All @@ -330,9 +320,7 @@ class CachedVideoPlayerPlus {
_cacheKey,
DateTime.timestamp().millisecondsSinceEpoch,
);
if (kDebugMode) {
debugPrint('Cached video [$dataSource] successfully.');
}
_debugPrint('Cached video [$dataSource] successfully.');
});
} else {
isCacheAvailable = true;
Expand Down Expand Up @@ -528,9 +516,7 @@ class CachedVideoPlayerPlus {
}

if (isCacheExpired) {
if (kDebugMode) {
debugPrint('Cache of [$url] expired. Removing...');
}
_debugPrint('Cache of [$url] expired. Removing...');
await cacheManager.removeFile(effectiveCacheKey);
cachedFile = null;
}
Expand All @@ -549,9 +535,14 @@ class CachedVideoPlayerPlus {
DateTime.timestamp().millisecondsSinceEpoch,
);

if (kDebugMode) {
debugPrint('Pre-Cached video [$url] successfully.');
}
_debugPrint('Pre-Cached video [$url] successfully.');
}
}
}

/// Checks if [kDebugMode] is enabled and prints a debug message.
void _debugPrint(String? message, {int? wrapWidth}) {
if (kDebugMode) {
debugPrint(message, wrapWidth: wrapWidth);
}
}