星空网 > 软件开发 > 操作系统

视频播放器边下边播(保存到沙盒,显示进度)

没怎么研究视频播放器,就在网上找了个,链接:https://github.com/835239104/KrVideoPlayerPlus

下载AFNetworking,

1.下载最新版的会报错,没有引入相关库

2.AFSecurityPolicy.m中:注释了一部分代码

#pragma mark - 这里改了 ------#warning - 这里改了 --------//#if !TARGET_OS_IOS && !TARGET_OS_WATCH//static NSData * AFSecKeyGetData(SecKeyRef key) {//  CFDataRef data = NULL;////  __Require_noErr_Quiet(SecItemExport(key, kSecFormatUnknown, kSecItemPemArmour, NULL, &data), _out);////  return (__bridge_transfer NSData *)data;////_out://  if (data) {//    CFRelease(data);//  }////  return nil;//}//#endifstatic BOOL AFSecKeyIsEqualToKey(SecKeyRef key1, SecKeyRef key2) {//#if TARGET_OS_IOS || TARGET_OS_WATCH  return [(__bridge id)key1 isEqual:(__bridge id)key2];//#else//  return [AFSecKeyGetData(key1) isEqual:AFSecKeyGetData(key2)];//#endif}

3.实现边下边播(我用的是一边在网上看一边下载,所以会有点卡)

/** * 下载文件 */- (void)downloadFileURL:(NSString *)aUrl savePath:(NSString *)aSavePath fileName:(NSString *)aFileName tag:(NSInteger)aTag{  NSFileManager *fileManager = [NSFileManager defaultManager];    //检查本地文件是否已存在  NSString *fileName = [NSString stringWithFormat:@"%@/%@", aSavePath, aFileName];    //检查附件是否存在  if ([fileManager fileExistsAtPath:fileName]) {     [self addVideoPlayerWithURL:[NSURL fileURLWithPath:fileName]];  }else{    //创建附件存储目录    if (![fileManager fileExistsAtPath:aSavePath]) {      [fileManager createDirectoryAtPath:aSavePath withIntermediateDirectories:YES attributes:nil error:nil];    }//     [self addVideoPlayerWithURL:[NSURL fileURLWithPath:fileName]];    [self addVideoPlayerWithURL:[NSURL URLWithString:aUrl]];    //下载附件    NSURL *url = [[NSURL alloc] initWithString:aUrl];    NSURLRequest *request = [NSURLRequest requestWithURL:url];        AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];    operation.inputStream  = [NSInputStream inputStreamWithURL:url];    operation.outputStream = [NSOutputStream outputStreamToFileAtPath:fileName append:NO];        //下载进度控制         [operation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {     NSLog(@"is download:%f", (float)totalBytesRead/totalBytesExpectedToRead);     }];        //已完成下载    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {//      NSData *audioData = [NSData dataWithContentsOfFile:fileName];      NSLog(@"完成下载");      //设置下载数据到res字典对象中并用代理返回下载数据NSData    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {      NSLog(@"下载失败");      //下载失败    }];        [operation start];  }}

注意:从本度读取路径:[NSURL fileURLWithPath:fileName]

在网上读取路径:[NSURL URLWithString:aUrl]

Demo百度云下载链接:http://pan.baidu.com/s/1c0bL9dQ




原标题:视频播放器边下边播(保存到沙盒,显示进度)

关键词:视频

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

美国跨境电商市场发展情况如何?美国电商市场行情分析:https://www.kjdsnews.com/a/1511201.html
跨境兴运:揭秘物流管理系统的优势与功能:https://www.kjdsnews.com/a/1511202.html
1039政策暂停,外贸人结汇何去何从?:https://www.kjdsnews.com/a/1511203.html
SDS百科全书,锂电池MSDS安全数据表UN运输要求,MSDS检测机构:https://www.kjdsnews.com/a/1511204.html
英文网站制作公司:公司中英文网站建设如何做更专业:https://www.kjdsnews.com/a/1511205.html
拼多多的直播“围城”:https://www.kjdsnews.com/a/1511206.html
深度解析:美国公司股东人数限制 :https://www.kjdsnews.com/a/1840835.html
深度解析:美国公司股东人数限制 :https://www.xlkjsw.com/news/88201.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流