MediaPlayerCacheManager

This class provides methods to manage cached media files.

enableAutoRemoveCache

Sets whether to delete cached media files automatically.

Future<void> enableAutoRemoveCache(bool enable);

Details

If you enable this function to remove cached media files automatically, when the cached media files exceed either the number or size limit you set, the SDK automatically deletes the least recently used cache file.

Parameters

enable
Whether to enable the SDK to delete cached media files automatically:
  • true: Delete cached media files automatically.
  • false: (Default) Do not delete cached media files automatically.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

getCacheDir

Gets the storage path of the cached media files.

Future<String> getCacheDir(int length);

Details

If you have not called the setCacheDir method to set the storage path for the media files to be cached before calling this method, you get the default storage path used by the SDK.

Parameters

length
An input parameter; the maximum length of the cache file storage path string.

Returns

  • The call succeeds, and the SDK returns the storage path of the cached media files.
  • < 0: Failure. See MediaPlayerReason.

getCacheFileCount

Gets the number of media files that are cached.

Future<int> getCacheFileCount();

Returns

  • ≥ 0: The call succeeds and returns the number of media files that are cached.
  • < 0: Failure. See MediaPlayerReason.

getMaxCacheFileCount

Gets the maximum number of media files that can be cached.

Future<int> getMaxCacheFileCount();

Details

By default, the maximum number of media files that can be cached is 1,000.

Returns

  • > 0: The call succeeds and returns the maximum number of media files that can be cached.
  • < 0: Failure. See MediaPlayerReason.

getMaxCacheFileSize

Gets the maximum size of the aggregate storage space for cached media files.

Future<int> getMaxCacheFileSize();

Details

By default, the maximum size of the aggregate storage space for cached media files is 1 GB. You can call the setMaxCacheFileSize method to set the limit according to your scenarios.

Returns

  • > 0: The call succeeds and returns the maximum size (in bytes) of the aggregate storage space for cached media files.
  • < 0: Failure. See MediaPlayerReason.

removeAllCaches

Deletes all cached media files in the media player.

Future<void> removeAllCaches();

Details

Note:

The cached media file currently being played will not be deleted.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

removeCacheByUri

Deletes a cached media file.

uture<void> removeCacheByUri(String uri);

Details

Note:

The cached media file currently being played will not be deleted.

Parameters

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

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

removeOldCache

Deletes a cached media file that is the least recently used.

Future<void> removeOldCache();

Details

You can call this method to delete a cached media file when the storage space for the cached files is about to reach its limit. After you call this method, the SDK deletes the cached media file that is least used.

Note:

The cached media file currently being played will not be deleted.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setCacheDir

Sets the storage path for the media files that you want to cache.

Future<void> setCacheDir(String path);

Details

Note:

Make sure RtcEngine is initialized before you call this method.

Parameters

path
The absolute path of the media files to be cached. Ensure that the directory for the media files exists and is writable.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setMaxCacheFileCount

Sets the maximum number of media files that can be cached.

Future<void> setMaxCacheFileCount(int count);

Parameters

count
The maximum number of media files that can be cached. The default value is 1,000.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setMaxCacheFileSize

Sets the maximum size of the aggregate storage space for cached media files.

Future<void> setMaxCacheFileSize(int cacheSize);

Parameters

cacheSize
The maximum size (bytes) of the aggregate storage space for cached media files. The default value is 1 GB.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.