iOS视频下载成功block回调
来源:互联网 发布:acg和sia知乎 编辑:程序博客网 时间:2024/06/09 17:32
一:在VC中调用下载类方法;
[HTXGolfVideoBufferMemory downLoadGolfVideoWithPath:littleVideoPath andURL:_url andWithDownLoadCompelition:^(NSString *path) {
// _url = path;
DSLog(@"下载完成地址 %@",path);
}];
二:在下载类方法中实现;
typedef void (^DownLoadCompeteBlcok)(NSString * path);
@interface HTXGolfVideoBufferMemory : NSObject
+ (void)createFile:(NSString*)path WithData:(NSData*)imgData andWithDownLoadCompelition : (DownLoadCompeteBlcok) downCompelition;;
+ (void) downLoadGolfVideoWithPath:(NSString *)littleVideoPath andURL:(NSString *)url andWithDownLoadCompelition : (DownLoadCompeteBlcok) downCompelition;
//创建缓存路径 并且下载到本地
+ (void)createFile:(NSString*)path WithData:(NSData*)imgData andWithDownLoadCompelition : (DownLoadCompeteBlcok) downCompelition{ // file
path = [path stringByAppendingString:@"OVER"];
[[NSFileManager defaultManager] createFileAtPath:path contents:nil attributes:nil];
// write
NSFileHandle*dataHandle = [NSFileHandle fileHandleForUpdatingAtPath:path] ;
[dataHandle writeData:imgData];
if (downCompelition) {
downCompelition(path);
}
// close
[dataHandle closeFile];
}
//创建多线程下载
+ (void) downLoadGolfVideoWithPath:(NSString *)littleVideoPath andURL:(NSString *)url andWithDownLoadCompelition:(DownLoadCompeteBlcok) downCompelition{
NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
NSData *littleVideoData = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
[self createFile:littleVideoPath WithData:littleVideoData andWithDownLoadCompelition:downCompelition];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
DSLog(@"视频缓存成功");
}];
}];
NSOperationQueue *queue = [[NSOperationQueue alloc]init];
[queue addOperation:operation];
}
0 0
- iOS视频下载成功block回调
- IOS 成功失败的Block写法
- iOS开发网络篇—文件下载 通过block回调
- 探索IOS版优酷视频下载
- iOS开发:下载视频到沙盒
- iOS block回调
- iOS block回调
- iOS Block回调
- Block实现iOS回调
- iOS 创建Label 提示“已成功下载”
- 黑马程序员—IOS加强视频—@block
- 成功解决android 网络视频边下载变播放。
- iOS非常重要的 block回调
- iOS非常重要的 block回调
- iOS 简单使用Block回调
- iOS M3U8视频的下载与播放
- 使用block封装的下载类-iOS开发
- iOS 开发-AFNetworking Block下载文件保存到沙盒
- javascript中的innerHTML是什么意思,怎么个用法?
- 划分树求第K大数
- JAVA EE---Servlet 学习第四天
- E - 叠筐
- C++基础 (二)有关于类
- iOS视频下载成功block回调
- VFW(video for window)技术-- 监控
- Linux操作系统
- mybatis和hibernate的区别
- HDU 2896 病毒侵袭
- 读书笔记:《MBA交不了你的创富课》(内附思维导图)
- angullarjs实现锚点楼层跳转
- 堂娜·哈拉维:赛博格宣言
- 1024! 末尾有多少个0?