The RedPreload SDK is a powerful tool for preloading videos and improving the user experience. It provides a range of features, including message callbacks, initialization with cache path and maximum size, and more. This guide will walk you through the steps to use the RedPreload SDK.
- Provides message callbacks for various events
- Supports initialization with cache path and maximum size
- Offers methods to open URLs and JSON with parameters and user data
- Supports stopping preload and deleting cache
To set the preload message callback, use the following method:
+ (void)setPreLoadMsgCallback:(RedPreLoadCallback)callback;
To initialize preload with cache path and maximum size, use the following method:
+ (void)initPreLoad:(NSString *)cachePath maxSize:(uint32_t)maxSize;
To initialize preload with cache path, maximum size(byte), and maximum directory capacity, use the following method:
+ (void)initPreLoad:(NSString *)cachePath maxSize:(uint32_t)maxSize maxdircapacity:(int64_t)maxdircapacity;
To open URLs with parameters and user data, use the following method:
/// Struct for RedPreloadParam
typedef struct {
NSString* cachePath; ///< Cache path
int64_t preloadSize; ///< Preload size bytes
NSString* referer; ///< Referer
int dnsTimeout; ///< DNS timeout
bool useHttps; ///< Use HTTPS or not
NSString* userAgent; ///< User agent
NSString* header; ///< Header
int64_t cache_max_dir_capacity; ///< Maximum directory capacity for cache
uint32_t cache_max_entries; ///< Maximum entries for cache
} RedPreloadParam;
+ (void)open:(NSURL *)url param:(RedPreloadParam)param userData:(void* _Nullable)userData;
To open JSON with parameters and user data, use the following method:
+ (void)openJson:(NSString *)jsonStr param:(RedPreloadParam)param userData:(void* _Nullable)userData;
To close URL preload task, use the following method:
+ (void)close:(NSURL *)url;
To close JSON preload task, use the following method:
+ (void)closeJson:(NSString *)jsonStr;
To stop all preload tasks, use the following method:
+ (void)stop;
To get cached size, use the following method:
+ (int64_t)getCachedSize:(NSString *)path uri:(NSString*)uri isFullUrl:(BOOL)isFullUrl;
To get all cached files, use the following method:
+ (NSArray<NSString *> *)getAllCachedFile:(NSString *)path;
To delete cache, use the following method:
+ (int)deleteCache:(NSString *)path uri:(NSString *)uri isFullUrl:(BOOL)isFullUrl;