All Products
Search
Document Center

ApsaraVideo VOD:Use local cache or preloading to improve playback experience

Last Updated:Nov 19, 2025

The local cache and preloading features of ApsaraVideo Player SDK improve the playback experience by enabling faster video startups and quicker responses when you drag the progress bar.

Important

For the code and implementation details of all features in this topic, refer to the API-Example sample project. You can adapt and extend the project based on best practices.

For specific implementations, refer to the configuration methods described below and the source code of the Video Preloading (Direct URL) module in the corresponding API-Example-Android and API-Example-iOS sample projects.

Background information

In scenarios where users watch videos repeatedly, fetching the video from the network for each playback consumes unnecessary bandwidth and increases the risk of stuttering. ApsaraVideo Player SDK provides local cache and preloading features that significantly improve video startup speed and the response speed when you drag the progress bar. This helps reduce playback stuttering.

Use local cache to improve playback experience

How it works

The local cache feature of ApsaraVideo Player SDK is enabled by the global AliPlayerGlobalSettings switch enableLocalCache. When this feature is enabled, the player automatically determines whether a video can be cached and whether the cache has expired based on its HTTP header information. You do not need to manage this process. To prevent excessive caching from using too much disk space, you can also configure the maximum cache size (maxCapacityMB) and the required minimum free disk space (freeStorageMB).

ApsaraVideo Player SDK distinguishes videos based on their playback URLs. However, some URLs contain authentication parameters, which means the playback URL for the same video can be different each time. To handle this, ApsaraVideo Player SDK provides the URL hash callback (setCacheUrlHashCallback). The player uses the return value of the callback to distinguish between videos. This return value can be considered the unique ID of the video.

For example, for a URL with authentication parameters, such as http://****.mp4?authKey=aaa, you can use the MD5 value of http://****.mp4 as the return value in the callback. This way, changes in the authentication parameters do not affect video identification. Similarly, if HTTP and HTTPS URLs point to the same video, you should return the same value to ensure the player uses the same cache file.

Scenarios

This feature is suitable for scenarios that involve repeated video viewing, such as loop playback in short video applications.

Configuration

Use preloading to improve playback experience

How it works

Preloading is an upgrade to the local cache feature. While one video plays, the next video is preloaded into the cache. This improves the startup speed when you switch to the next video. For list playback scenarios with fast scrolling, you can combine preloading with dual instances to improve the viewing experience. First, enable the local cache feature. Then, while the current video is playing and has a sufficient buffer, you can use another player instance to prepare the next video. When you scroll to the next video, it starts playing immediately. After the buffer for the second instance is full, you can continue to preload subsequent videos to increase the size of the video cache.

Scenarios

This feature is suitable for scenarios such as list playback with fast scrolling.

Configuration