IMediaPlayerCacheManager
This class provides methods to manage cached media files in the media player.
enableAutoRemoveCache
Sets whether to enable the automatic cache file removal feature.
abstract enableAutoRemoveCache(enable: boolean): number;
When automatic cache file removal is enabled, if the number or size of cached media files in the player exceeds the set limit, the SDK automatically removes the least recently used cached file.
Parameters
- enable
- Whether to automatically remove cached files:
- true: Enable automatic cache file removal.
- false: (Default) Disable automatic cache file removal.
Return Values
- 0: Success.
- < 0: Failure. See MediaPlayerReason.
getCacheDir
Gets the storage path of cached files.
abstract getCacheDir(length: number): string;
If you do not call the setCacheDir method to customize the cache file storage path before calling this method, it 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 file.
- < 0: Failure. See MediaPlayerReason.
getCacheFileCount
Gets the total number of currently cached media files.
abstract getCacheFileCount(): number;
Return Values
- ≥ 0: Success. Returns the total number of currently cached media files.
- < 0: Failure. See MediaPlayerReason.
getMaxCacheFileCount
Gets the maximum number of cached files set.
abstract getMaxCacheFileCount(): number;
The SDK's default maximum number of cached files is 1000.
Return Values
- > 0: Success. Returns the maximum number of cached files.
- < 0: Failure. See MediaPlayerReason.
getMaxCacheFileSize
Gets the upper limit of the total cache size for cached files.
abstract getMaxCacheFileSize(): number;
The SDK's default upper limit for the total cache size of cached files is 1GB. You can call the setMaxCacheFileSize method to customize the total cache size limit.
Return Values
- > 0: Success. Returns the total cache size limit of cached files, in bytes.
- < 0: Failure. See MediaPlayerReason.
getMediaPlayerCacheManager
Gets an instance of IMediaPlayerCacheManager.
export function getMediaPlayerCacheManager(): IMediaPlayerCacheManager {
return new IMediaPlayerCacheManagerImpl();
}
Before calling other APIs under the IMediaPlayerCacheManager class, you need to call this method to get an instance of the media player cache manager.
Timing
Call this method after initializing IRtcEngine.
Return Values
IMediaPlayerCacheManager instance.
removeAllCaches
Deletes all cached media files in the media player.
abstract removeAllCaches(): number;
Return Values
- 0: Success.
- < 0: Failure. See MediaPlayerReason.
removeCacheByUri
Deletes a specified cached media file.
abstract removeCacheByUri(uri: string): number;
Parameters
- uri
- The URI (Uniform Resource Identifier) of the cached file to delete. Used to identify the media file.
Return Values
- 0: Success.
- < 0: Failure. See MediaPlayerReason.
removeOldCache
Deletes the least recently used cached media file in the media player.
abstract removeOldCache(): number;
When cached media files occupy too much space, you can call this method to clean up the cache. After calling this method, the SDK deletes the least recently used cached media file.
Return Values
- 0: Success.
- < 0: Failure. See MediaPlayerReason.
setCacheDir
Sets the storage path for media files to be cached.
abstract setCacheDir(path: string): number;
Parameters
- path
- The absolute path where cached files are stored. Ensure the specified directory exists and is writable.
Return Values
- 0: Success.
- < 0: Failure. See MediaPlayerReason.
setMaxCacheFileCount
Sets the maximum number of cached media files.
abstract setMaxCacheFileCount(count: number): number;
Parameters
- count
- The maximum number of media files that can be cached. The default value is 1000.
Return Values
- 0: Success.
- < 0: Failure. See MediaPlayerReason.
setMaxCacheFileSize
Sets the maximum total cache size for media files.
abstract setMaxCacheFileSize(cacheSize: number): number;
Parameters
- cacheSize
- The maximum total cache size for media files, in bytes. The default is 1 GB.
Return Values
- 0: Success.
- < 0: Failure. See MediaPlayerReason.