离线下载实现逻辑

  • 第一步是先按照开发环境配置搭建好工程环境

  • 第二步(SDK)

    把 TalkfunSDKFramework.framework 文件拖入工程。 SDK

  • 第三步(点播下载控制器)View Controller 如图所示: downloadVC

添加引用

  • 在上述DownloadListController.m中添加引用#import "TalkfunDownloadManager.h"

添加声明属性

  • DownloadListController.m中添加属性
    • TalkfunDownloadManager * downloadManager
#import "DownloadListController.h"
#import "TalkfunDownloadManager.h"

@interface DownloadListController ()

//下载管理对象
@property (nonatomic,strong) TalkfunDownloadManager * downloadManager;

@end

创建下载的对象

  • 以单例的形式实例化下载对象
self.downloadManager = [TalkfunDownloadManager shareManager];

创建下载任务并启动下载

  • 支持将课程数据下载到本地,在无网络环境正常播放。
  • 进入回放时,需要传入回放的access_token和playbackID,SDK会根据传入的access_token和playbackID从本地检索是否有该课程的缓存文件,如果有缓存则读取本地缓存播放,否则去请求网络。

//创建下载任务
 [self.downloadManager appendDownloadWithAccessToken: access_token playbackID:self.playbackID title:nil];

 //启动下载
 [self.downloadManager startDownload:self.playbackID];

下载进度

  • 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离线观看

实例:


  NSArray * playbackList = self.downloadManager.getDownloadList;

 TalkfunDownloadListModel * model = playbackList[indexPath.row];

 if (model.downloadStatus == TalkfunDownloadStatusFinish) {


  //TODO:设置点播控制器数据
 TalkfunPlaybackViewController * playbackVC = [TalkfunPlaybackViewController new];
 playbackVC.modalPresentationStyle = UIModalPresentationFullScreen;
 playbackVC.playbackID = model.playbackID;
 playbackVC.res = @{@"data":@{@"access_token":model.access_token},TalkfunPlaybackID:model.playbackID};
 playbackVC.downloadCompleted = YES;//下载完成
 [self presentViewController:playbackVC animated:NO completion:nil];

}
Copyright Talkfun all right reserved,powered by Gitbook修订时间: 2021-05-25 18:38:37

results matching ""

    No results matching ""