离线下载实现逻辑
第一步是先按照开发环境配置搭建好工程环境
第二步
- 把 courseDownload 整个文件夹拖入工程
- 把 TFPublic(工具类)整个文件夹拖入工程
- 把 Assets.xcassets的FDemoAssetss文件夹拖入工程
let downloadManager = TalkfunDownloadManager.share()
创建下载的对象
创建下载任务并启动下载
- 支持将课程数据下载到本地,在无网络环境正常播放。
- 进入回放时,需要传入回放的access_token和playbackID,SDK会根据传入的access_token和playbackID从本地检索是否有该课程的缓存文件,如果有缓存则读取本地缓存播放,否则去请求网络。
let access_token = "fsdfsdfsdfasdfasfs"
let playback_ID = "123"
//创建下载任务
self.downloadManager.appendDownload(withAccessKey: token, playbackID: playback_ID, title: "")
//启动下载
self.downloadManager.startDownload(playback_ID)
下载进度
- TalkfunDownloadManagerDelegate
- (void)downloadProgress:(TalkfunDownloadProgressModel*_Nullable)progressModel
- TalkfunDownloadProgressModel 参数
@interface TalkfunDownloadProgressModel : NSObject
@property(nonatomic,strong)NSString* _Nullable playbackID;//课程id
@property(nonatomic,assign)CGFloat totalSize;//课程总大小
@property(nonatomic,assign)CGFloat downloadedSize;//已下载的大小
@end
下载状态
- TalkfunDownloadManagerDelegate
- (void)downloadStatus:(TalkfunDownloadStatusModel*_Nullable)statusModel
- TalkfunDownloadStatusModel 参数
@interface TalkfunDownloadStatusModel : NSObject
@property(nonatomic,strong)NSString* _Nullable playbackID;//课程id
@property(nonatomic,assign)CGFloat downloadedSize;//已下载的大小
@property(nonatomic,assign)CGFloat duration; //课程长度
@property(nonatomic,assign)CGFloat totalSize; ///课程总大小
@property(nonatomic,assign)TalkfunDownloadStatus downloadStatus;
@property (nonatomic, copy) NSString * _Nullable thumb;
@end
下载发生错误
- TalkfunDownloadManagerDelegate
- (void)downloadError:(TalkfuError *_Nullable)error
- TalkfuError 参数
@interface TalkfuError : NSObject
@property(nonatomic,strong)NSString *_Nullable playbackID;//课程id
@property(nonatomic,strong)NSString *_Nullable reasonDescription;//原因描述
@property(nonatomic,assign)NSString *_Nullable statusCode;//状态码
@property(nonatomic,assign)NSString *_Nullable URL;
@end
下载完成后可通过课程access_token离线观看
```