IMediaPlayerCacheManager

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

EnableAutoRemoveCache

Enables or disables automatic cache file removal.

public abstract int EnableAutoRemoveCache(bool enable);

When automatic cache file removal is enabled, if the number of cached media files or the total cache size exceeds the limit you set, the SDK automatically deletes the least recently used cache file.

Parameters

enable
Whether to enable automatic cache file removal:
  • true: Enable automatic cache file removal.
  • false: (default) Disable automatic cache file removal.

Return Values

GetCacheDir

Gets the storage path of cached files.

public abstract int GetCacheDir(out string path, int length);

If you have not called SetCacheDir to customize the cache file storage path before calling this method, it returns the default cache file storage path used by the SDK.

Parameters

path
Output parameter. Storage path of cached files.
length
Input parameter. Maximum length of the cache file storage path string. Fill in based on the string obtained in path.

Return Values

GetCacheFileCount

Gets the total number of currently cached media files.

public abstract int GetCacheFileCount();

Return Values

  • ≥ 0: Success. Returns the total number of currently cached media files.
  • < 0: Failure. See MEDIA_PLAYER_REASON.

GetMaxCacheFileCount

Gets the maximum number of cache files set.

public abstract int GetMaxCacheFileCount();

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

Return Values

  • > 0: The method call succeeds and returns the maximum number of cache files.
  • < 0: The method call fails. See MEDIA_PLAYER_REASON.

GetMaxCacheFileSize

Gets the maximum total cache size of cached media files set.

public abstract Int64 GetMaxCacheFileSize();

The default maximum total cache size of cache files in the SDK is 1 GB. You can call the SetMaxCacheFileSize method to customize the maximum total cache size.

Return Values

  • > 0: The method call succeeds and returns the maximum total cache size of cache files in bytes.
  • < 0: The method call fails. See MEDIA_PLAYER_REASON.

GetMediaPlayerCacheManager

Gets the IMediaPlayerCacheManager instance.

public abstract IMediaPlayerCacheManager GetMediaPlayerCacheManager();

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

Note: Since the media player cache manager object 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.

public abstract int RemoveAllCaches();
Note: This method does not delete cached media files that are currently playing.

Return Values

RemoveCacheByUri

Deletes the specified cached media file.

public abstract int RemoveCacheByUri(string uri) ;
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, which can be used to identify the media file.

Return Values

RemoveOldCache

Deletes the least recently used cached media file in the media player.

public abstract int 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.

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

Return Values

SetCacheDir

Sets the storage path for media files to be cached.

public abstract int SetCacheDir(string path) ;
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 maximum number of cached media files.

public abstract int SetMaxCacheFileCount(int count);

Parameters

count
The maximum number of media files that can be cached. The default value is 1000.

Return Values

SetMaxCacheFileSize

Sets the maximum total cache size of cached media files.

public abstract int SetMaxCacheFileSize(Int64 cacheSize);

Parameters

cacheSize
The maximum total cache size of cached media files in bytes. The default is 1 GB.

Return Values