MediaPlayerCacheManager
This class provides methods for managing cached media files in the media player.
enableAutoRemoveCache
Enables or disables the automatic cache file removal feature.
Future<void> enableAutoRemoveCache(bool enable);
When automatic cache file removal is enabled, if the number or total size of cached media files in the player exceeds the set limit, the SDK automatically removes the least recently used cache file.
Parameters
- enable
- Whether to enable automatic cache file removal:
- true: Enables automatic cache file removal.
- false: (Default) Disables automatic cache file removal.
Return Values
- < 0: Failure. See MediaPlayerReason.
getCacheDir
Gets the storage path of the cached files.
Future<String> getCacheDir(int length);
If you have not called the setCacheDir method to customize the cache file storage path before calling this method, the method returns the SDK's default cache file storage path.
Parameters
- length
- Input parameter. The maximum length of the cache file storage path string.
Return Values
- On success, returns the storage path of the cached files.
- < 0: Failure. See MediaPlayerReason.
getCacheFileCount
Gets the total number of currently cached media files.
Future<int> getCacheFileCount();
Return Values
- ≥ 0: Success. Returns the total number of currently cached media files.
- < 0: Failure. See MediaPlayerReason.
getMaxCacheFileCount
Gets the maximum number of cache files set.
Future<int> getMaxCacheFileCount();
The default maximum number of cache files in the SDK is 1000.
Return Values
- > 0: Success. Returns the maximum number of cache files.
- < 0: Failure. See MediaPlayerReason.
getMaxCacheFileSize
Gets the maximum total cache size of cache files set.
Future<int> getMaxCacheFileSize();
The default maximum total cache size of cache files in the SDK is 1GB. You can call the setMaxCacheFileSize method to customize the limit.
Return Values
- > 0: Success. Returns the maximum total cache size in bytes.
- < 0: Failure. See MediaPlayerReason.
getMediaPlayerCacheManager
Gets the MediaPlayerCacheManager instance.
MediaPlayerCacheManager getMediaPlayerCacheManager()
Before calling other APIs under the MediaPlayerCacheManager class, you need to call this method to get an instance of the media player cache manager.
Timing
Call this method after initializing RtcEngine.
Return Values
MediaPlayerCacheManager instance.
removeAllCaches
Deletes all cached media files in the media player.
Future<void> removeAllCaches();
Return Values
- < 0: Failure. See MediaPlayerReason.
removeCacheByUri
Deletes a specified cached media file.
uture<void> removeCacheByUri(String uri);
Parameters
- uri
- The URI (Uniform Resource Identifier) of the cache file to be deleted, which can be used to identify the media file.
Return Values
- < 0: Failure. See MediaPlayerReason.
removeOldCache
Deletes the least recently used cached media file in the media player.
Future<void> removeOldCache();
When cached media files occupy too much space, you can call this method to clean up cache files. After calling this method, the SDK deletes the least recently used cached media file.
Return Values
- < 0: Failure. See MediaPlayerReason.
setCacheDir
Sets the storage path for media files to be cached.
Future<void> setCacheDir(String path);
Parameters
- path
- The absolute path for storing cached files. Make sure the specified directory exists and is writable.
Return Values
- < 0: Failure. See MediaPlayerReason.
setMaxCacheFileCount
Sets the maximum number of cached media files.
Future<void> setMaxCacheFileCount(int count);
Parameters
- count
- The maximum number of media files that can be cached. The default value is 1000.
Return Values
- < 0: Failure. See MediaPlayerReason.
setMaxCacheFileSize
Sets the upper limit of the total cache size for media files.
Future<void> setMaxCacheFileSize(int cacheSize);
Parameters
- cacheSize
- The total cache size limit for media files, in bytes. The default is 1 GB.
Return Values
- < 0: Failure. See MediaPlayerReason.