Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
aebfb22
♻️ Extract `IVideoPlayerStorage`
AlexV525 Sep 1, 2025
ce4c028
🚸 Allow changing the default cache manager and storage
AlexV525 Sep 1, 2025
6d00b83
🐛 Export entries
AlexV525 Sep 1, 2025
2e87718
🔥 Remove the constructor
AlexV525 Sep 1, 2025
e5e2d35
⚡️ Address review comments from @OutdatedGuy
AlexV525 Sep 1, 2025
a379413
♻️ Extract `IVideoPlayerStorage` and `IVideoPlayerMetadataStorage`
AlexV525 Sep 1, 2025
5cd67d9
🔥 Provide type alias deprecations
AlexV525 Sep 1, 2025
0c77ca7
🐛 Fix exports
AlexV525 Sep 1, 2025
62f683b
🔥 Flatten `IVideoPlayerStorage`
AlexV525 Sep 25, 2025
70eec5f
🚀 Add example
AlexV525 Sep 25, 2025
926385f
🚀 Add metadata storage example
AlexV525 Sep 25, 2025
1674b61
⚡️ Improve `MemoryVideoPlayerMetadataStorage`
AlexV525 Sep 25, 2025
ce50c4b
🐛 Fix incorrect comment's placement
AlexV525 Sep 28, 2025
a5c398f
🙈 Update ignored files
AlexV525 Oct 23, 2025
c9a7145
✨ `IVideoPlayerMetadataStorage.keys`
AlexV525 Oct 23, 2025
4d069fb
🐛 Fix storage referencing issues in the example
AlexV525 Oct 23, 2025
00df711
🐛 Fix Darwin compile
AlexV525 Oct 23, 2025
a226664
🚸 Improve example texts display
AlexV525 Oct 23, 2025
69c89e3
📝 Comments correction and improvement
AlexV525 Nov 12, 2025
8b6ad99
Revert "🐛 Fix Darwin compile"
AlexV525 Nov 12, 2025
330f516
Revert "🙈 Update ignored files"
AlexV525 Nov 12, 2025
93c1ea6
🔥 Remove references with the custom cache manager in the example
AlexV525 Nov 12, 2025
6e3d184
♻️ Move `MemoryVideoPlayerMetadataStorage`
AlexV525 Nov 12, 2025
b9aa124
💡 Update comment
AlexV525 Dec 5, 2025
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
30 changes: 30 additions & 0 deletions example/lib/impl/memory_metadata_storage.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:cached_video_player_plus/cached_video_player_plus.dart'
show IVideoPlayerMetadataStorage;

/// Stores video metadata in memory.
class MemoryVideoPlayerMetadataStorage implements IVideoPlayerMetadataStorage {
final _data = <String, int>{};

@override
Set<String> get keys => _data.keys.toSet();

@override
Future<int?> read(String key) {
return Future.value(_data[key]);
}

@override
Future<void> write(String key, int value) {
return Future.sync(() => _data[key] = value);
}

@override
Future<void> remove(String key) {
return Future.sync(() => _data.remove(key));
}

@override
Future<void> erase() {
return Future.sync(() => _data.clear());
}
}
14 changes: 9 additions & 5 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,15 @@ class _FeatureCard extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
title,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w600,
),
FittedBox(
fit: BoxFit.scaleDown,
child: Text(
title,
style:
Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w600,
),
),
),
const SizedBox(height: 4),
Text(
Expand Down
78 changes: 59 additions & 19 deletions example/lib/pages/advance_cache_management_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import 'package:cached_video_player_plus/cached_video_player_plus.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '../impl/memory_metadata_storage.dart';

const _keyPrefix = 'cached_video_player_plus_caching_time_of_';

Expand Down Expand Up @@ -57,11 +58,13 @@ class _AdvanceCacheManagementPageState
maxNrOfCacheObjects: 20,
),
);
final _asyncPrefs = SharedPreferencesAsync();
final _customMetadataStorage = MemoryVideoPlayerMetadataStorage();

int _selectedIndex = 0;
String _customKey = '';
bool _forceFetch = false;
bool _overrideCacheManager = false;
bool _overrideMetadataStorage = false;
bool _isLoading = false;
bool _isCaching = false;
bool _isClearing = false;
Expand All @@ -80,19 +83,21 @@ class _AdvanceCacheManagementPageState
setState(() => _isLoading = true);

try {
final allKeys = await _asyncPrefs.getKeys();
final metadataStorage = CachedVideoPlayerPlus.metadataStorage;
final allKeys = await metadataStorage.keys;
final videoKeys = allKeys.where((key) => key.startsWith(_keyPrefix));

final cachedFiles = await Future.wait(
videoKeys.map((key) async {
final cachedFile = await _customCacheManager.getFileFromCache(key);
final cachedFile =
await CachedVideoPlayerPlus.cacheManager.getFileFromCache(key);
if (cachedFile == null) return null;

return _CachedFileInfo(
cachedFile,
key.replaceFirst(_keyPrefix, ''),
DateTime.fromMillisecondsSinceEpoch(
(await _asyncPrefs.getInt(key))!,
(await metadataStorage.read(key))!,
),
await cachedFile.file.length(),
);
Expand All @@ -114,7 +119,6 @@ class _AdvanceCacheManagementPageState
await CachedVideoPlayerPlus.preCacheVideo(
Uri.parse(_videoUrls[_selectedIndex].url),
cacheKey: _customKey,
cacheManager: _customCacheManager,
invalidateCacheIfOlderThan:
_forceFetch ? Duration.zero : const Duration(days: 42),
);
Expand All @@ -129,9 +133,7 @@ class _AdvanceCacheManagementPageState
setState(() => _isClearing = true);

try {
await CachedVideoPlayerPlus.clearAllCache(
cacheManager: _customCacheManager,
);
await CachedVideoPlayerPlus.clearAllCache();
} finally {
if (mounted) setState(() => _isClearing = false);
_fetchCacheInfo();
Expand All @@ -140,10 +142,7 @@ class _AdvanceCacheManagementPageState

Future<void> _deleteCacheFile(String cacheKey) async {
try {
await CachedVideoPlayerPlus.removeFileFromCacheByKey(
cacheKey,
cacheManager: _customCacheManager,
);
await CachedVideoPlayerPlus.removeFileFromCacheByKey(cacheKey);
} finally {
_fetchCacheInfo();
}
Expand Down Expand Up @@ -205,13 +204,54 @@ class _AdvanceCacheManagementPageState
],
),
const SizedBox(height: 12),
Row(
Wrap(
spacing: 12.0,
runSpacing: 12.0,
children: [
const Text('Force fetch latest:'),
const SizedBox(width: 12),
Switch.adaptive(
value: _forceFetch,
onChanged: (value) => setState(() => _forceFetch = value),
Row(
mainAxisSize: MainAxisSize.min,
children: [
const Text('Force fetch latest:'),
const SizedBox(width: 12),
Switch.adaptive(
value: _forceFetch,
onChanged: (value) => setState(() => _forceFetch = value),
),
],
),
Row(
mainAxisSize: MainAxisSize.min,
children: [
const Text('Override default cache manager:'),
const SizedBox(width: 12),
Switch.adaptive(
value: _overrideCacheManager,
onChanged: (value) {
CachedVideoPlayerPlus.cacheManager = value
? _customCacheManager
: CachedVideoPlayerPlus.defaultCacheManager;
setState(() => _overrideCacheManager = value);
_fetchCacheInfo();
},
),
],
),
Row(
mainAxisSize: MainAxisSize.min,
children: [
const Text('Override default metadata storage:'),
const SizedBox(width: 12),
Switch.adaptive(
value: _overrideMetadataStorage,
onChanged: (value) {
CachedVideoPlayerPlus.metadataStorage = value
? _customMetadataStorage
: CachedVideoPlayerPlus.defaultMetadataStorage;
setState(() => _overrideMetadataStorage = value);
_fetchCacheInfo();
},
),
],
),
],
),
Expand Down
3 changes: 3 additions & 0 deletions lib/cached_video_player_plus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@
library;

export 'src/cached_video_player_plus.dart';
export 'src/i_video_player_metadata_storage.dart';
export 'src/video_cache_manager.dart';
export 'src/video_player_metadata_storage.dart';
Loading