Version: 2.67.0

Aditional Features of Cache API


This articles helps to describes additional features for Offline Playback using different properties/methods of THEO Caching API.

The various status of the caching API are as follows:

  • Idle: This means that the task has been created, but not downloading content at the moment.
  • Loading: This means that the task is currently downloading the content.
  • Done: This means that the task has finished downloading all content.
  • Error: This means that the task has encountered an error while downloading or evicting content.
  • Evicted: This means that all data associated with the task has been removed because the task expired or the user invoked the remove method.

Code Example 

How to Pause or Resume a downloading Stream:

// For Android SDK
private void startAndPauseTask(CachingTask task) {
// Below will move from "Loading" status to "Idle" and pause the downloading
// Below will move from "Idle" status to "Loading" and resume the downloading
// For iOS SDK
// pausing a caching task
// resuming a caching task

How to check size and progression of downloading Stream:

After creating a caching task, it is possible to check an estimate for the total size of the caching task on disk, and the current progression in bytes (stored).

// For Android SDK
private void checkStorageRequirements(CachingTask unstartedTask) {
// We can get an estimate for the amount of space this task will consume. This will be ready once the manifest is preprocessed when the task is created. Starting is not necessary
// ... Additional logic here
// At any time, we can check the current amount of bytes cached by the task
// For iOS SDK
if let cachingTask = cachingTask {
// Listen for state change events
_ = cachingTask.addEventListener(type: CachingTaskEventTypes.STATE_CHANGE, listener: { event in
// Listen for progress events
_ = cachingTask.addEventListener(type: CachingTaskEventTypes.PROGRESS, listener: { event in
// percentage cached
// total bytes cached
// the amount of seconds cached
// the range that is cached
for timeRange in cachingTask.cached {
print(timeRange.start, timeRange.end)

How to delete a downloaded Stream:

Below example deletes all the downloaded assets, while an individual file can also be deleted as per your user by comparing the source

// For Android SDK
privatevoid cleanCache() {
for (CachingTask task: sharedInstance.getCache().getTasks()) {
//To delete all the downloaded assets
// For iOS SDK
func cleanCache() {
for cachingTask in THEOplayer.cache.tasks {
print("Will remove caching task \(cachingTask.source.sources[0].src)")
//To delete a particular asset
if cachingTask.source.sources[0].src == source{