This guide provides step-by-step instructions on how to initialize and configure the Android SDK for our open-source video preload. When use preload to download video data, your MediaPlayer can start more faster than normal. So we highly recommand you combine the RedPreload SDK and RedPlayer SDK to usage.
- Supports preload videos in both normal URL and JSON formats
- Provides options to configure the preload, such as download size, download cache dir
- Supports monitoring preload status and callbacks for various events
IMediaPreoad mMediaPreload = new RedMediaPreload();
pubic class VideoCacheRequest {
public String name; // preload task name
public String videoUrl; // preload resource url
public String videoJson; // preload resource json url, high than videoUrl
public String cacheDir; // preload cache dir
public String cacheSize; // preload data size
public String cacheDirMaxSize; // preload dir max size: when beyond, start LRU
public String cacheDirMaxEntries; // preload dir max file count: when beyond,start LRU
}
preloadRequest = new VideoCacheRequest()
mMediaPreload.start(preloadRequest)
By following the three steps above, you can complete the use of the Media Preload SDK
void start(VideCacheRequest request); // start preload
void stop(); // stop preload
void release(); // release preload module: can't start again, need recreate
long getAllCacheFilePaths(String cacheDir); // get the dir's all files
long deleteCacheFile(String cacheDir, String url); // delete the cache dir task: the url is the key of preload task
float getCacheFileRealSize(String cacheDir, String url); // get the file real download size: not the file size
- PreloadCacheListener This interface runs through the entire lifecycle of the preload, it will be called with many different event.
interface PreloadCacheListener {
/**
* @param cacheFilePath file absolute path
* @param cacheFileSize file size, unit: b
* @param request origin preload request
*/
void onPreloadSuccess(String cacheFilePath, long cacheFileSize, VideoCacheRequest request);
/**
* @param errorMsg preload error msg
* @param request origin preload request
*/
void onPreloadError(long errorMsg, VideoCacheRequest request);
/**
* @param request origin preload request
*/
void onPreloadStart(VideoCacheRequest request);
}
void addPreloadCacheListener(PreloadCacheListener listener); // add the preload status listener
void removePreloadCacheListener(PreloadCacheListener listener); // remove the preload status listener