Agora Java API Reference for Android

Public Member Functions | List of all members
io.agora.mediaplayer.IMediaPlayerCacheManager Interface Reference

## Public Member Functions
int | removeAllCaches ()
| Deletes all cached media files in the media player. More...
int | removeOldCache ()
| Deletes a cached media file that is the least recently used. More...
int | removeCacheByUri (String uri)
| Deletes a cached media file. More...
int | setCacheDir (String path)
| Sets the storage path for the media files that you want to cache. More...
int | setMaxCacheFileCount (int count)
| Sets the maximum number of media files that can be cached. More...
int | setMaxCacheFileSize (long cacheSize)
| Sets the maximum size of the aggregate storage space for cached media files. More...
int | enableAutoRemoveCache (boolean enable)
| Sets whether to delete cached media files automatically. More...
String | getCacheDir ()
| Gets the storage path of the cached media files. More...
int | getMaxCacheFileCount ()
| Gets the maximum number of media files that can be cached. More...
long | getMaxCacheFileSize ()
| Gets the maximum size of the aggregate storage space for cached media files. More...
int | getCacheFileCount ()
| Gets the number of media files that are cached. More...

## Member Function Documentation

## ◆ removeAllCaches()

int io.agora.mediaplayer.IMediaPlayerCacheManager.removeAllCaches | ( |  | ) |

Deletes all cached media files in the media player.

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

Returns
  - 0: Success.
  - < 0: Failure. See `MediaPlayerReason`.

## ◆ removeOldCache()

int io.agora.mediaplayer.IMediaPlayerCacheManager.removeOldCache | ( |  | ) |

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

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.

Returns
  - 0: Success.
  - < 0: Failure. See `MediaPlayerReason`.

## ◆ removeCacheByUri()

int io.agora.mediaplayer.IMediaPlayerCacheManager.removeCacheByUri | ( | String | uri | ) |

Deletes a cached media file.

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.

Returns
  - 0: Success.
  - < 0: Failure. See `MediaPlayerReason`.

## ◆ setCacheDir()

int io.agora.mediaplayer.IMediaPlayerCacheManager.setCacheDir | ( | String | path | ) |

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

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.

Returns
  - 0: Success.
  - < 0: Failure. See `MediaPlayerReason`.

## ◆ setMaxCacheFileCount()

int io.agora.mediaplayer.IMediaPlayerCacheManager.setMaxCacheFileCount | ( | int | count | ) |

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

Parameters

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

Returns
  - 0: Success.
  - < 0: Failure. See `MediaPlayerReason`.

## ◆ setMaxCacheFileSize()

int io.agora.mediaplayer.IMediaPlayerCacheManager.setMaxCacheFileSize | ( | long | cacheSize | ) |

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

Parameters

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

Returns
  - 0: Success.
  - < 0: Failure. See `MediaPlayerReason`.

## ◆ enableAutoRemoveCache()

int io.agora.mediaplayer.IMediaPlayerCacheManager.enableAutoRemoveCache | ( | boolean | enable | ) |

Sets whether to delete cached media files automatically.

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.

Returns
  - 0: Success.
  - < 0: Failure. See `MediaPlayerReason`.

## ◆ getCacheDir()

String io.agora.mediaplayer.IMediaPlayerCacheManager.getCacheDir | ( |  | ) |

Gets the storage path of the cached media files.

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.

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

## ◆ getMaxCacheFileCount()

int io.agora.mediaplayer.IMediaPlayerCacheManager.getMaxCacheFileCount | ( |  | ) |

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

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()

long io.agora.mediaplayer.IMediaPlayerCacheManager.getMaxCacheFileSize | ( |  | ) |

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

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`.

## ◆ getCacheFileCount()

int io.agora.mediaplayer.IMediaPlayerCacheManager.getCacheFileCount | ( |  | ) |

Gets the number of media files that are cached.

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