IMediaPlayerCacheManager

This class provides methods to manage cached media files in the media player.

enableAutoRemoveCache

Sets whether to enable automatic removal of cache files.

abstract enableAutoRemoveCache(enable: boolean): number;

After enabling automatic removal of cache files, when the number or total size of cached media files in the player exceeds the set limit, the SDK will automatically remove the least recently used cache file.

Parameters

enable
Whether to automatically remove cache files:
  • true: Enable automatic removal of cache files.
  • false: (Default) Disable automatic removal of cache files.

Return Values

getCacheDir

Gets the storage path of the cache file.

abstract getCacheDir(length: number): string;

If you have not called the setCacheDir method to customize the storage path of the cache file 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

  • The storage path of the cache file, if the method call succeeds.
  • < 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 upper limit of the number of cache files set.

abstract getMaxCacheFileCount(): number;

The default upper limit of the number of cache files in the SDK is 1000.

Return Values

  • > 0: Success. Returns the upper limit of the number of cache files.
  • < 0: Failure. See MediaPlayerReason.

getMaxCacheFileSize

Gets the upper limit of the total cache size of cache files set.

abstract getMaxCacheFileSize(): number;

The default upper limit of the total cache size in the SDK is 1GB. You can call the setMaxCacheFileSize method to customize the upper limit of the total cache size.

Return Values

  • > 0: Success. Returns the upper limit of the total cache size of cache files in bytes.
  • < 0: Failure. See MediaPlayerReason.

getMediaPlayerCacheManager

Gets the IMediaPlayerCacheManager instance.

export function getMediaPlayerCacheManager(): IMediaPlayerCacheManager {
  return new IMediaPlayerCacheManagerImpl();
}

Before calling other APIs under the IMediaPlayerCacheManager class, you must call this method to get a media player cache manager instance.

Note: Since the media player cache manager is a singleton, multiple calls to this method return the same instance.

Timing

Call this method after initializing IRtcEngine.

Return Values

IMediaPlayerCacheManager instance.

removeAllCaches

Deletes all cached media files in the media player.

abstract removeAllCaches(): number;
Note: This method does not delete cached media files that are currently playing.

Return Values

removeCacheByUri

Deletes the specified cached media file.

abstract removeCacheByUri(uri: string): number;
Note: This method does not delete cached media files that are currently playing.

Parameters

uri
The URI (Uniform Resource Identifier) of the cache file to be deleted, used to identify the media file.

Return Values

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 cache files. After calling this method, the SDK deletes the least recently used cached media file.

Note: When you call this method to delete cached media files, cached media files that are currently playing will not be deleted.

Return Values

setCacheDir

Sets the storage path for media files to be cached.

abstract setCacheDir(path: string): number;
Note: This method must be called after initializing IRtcEngine.

Parameters

path
The absolute path where the cache files are stored. Make sure the specified directory exists and is writable.

Return Values

setMaxCacheFileCount

Sets the upper limit on the number of cached media files.

abstract setMaxCacheFileCount(count: number): number;

Parameters

count
The upper limit on the number of media files that can be cached. The default value is 1000.

Return Values

setMaxCacheFileSize

Sets the upper limit of the total cache size for cached media files.

abstract setMaxCacheFileSize(cacheSize: number): number;

Parameters

cacheSize
The upper limit of the total cache size for cached media files, in bytes. The default is 1 GB.

Return Values