post上传视频文件到服务端
2015-12-29 11:56
603 查看
UIButton *videoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
videoBtn.frame = CGRectMake(20, 20, SCREENWIDTH/3, 40);
//添加视频模块
- (void)getVideoAction:(UIButton *)sender {
[SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeBlack];
// aview.text = @”请阅读以下诗歌:锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦!”;
// aview.text = responseObject[@”message”];
[aview setTextColor:[UIColor orangeColor]];
[aview setFont:[UIFont fontWithName:@”Helvetica-Bold” size:18]];
[aview setTextAlignment:NSTextAlignmentCenter];
aview.numberOfLines = 0;
aview.backgroundColor = [UIColor clearColor];
[pickerView.view addSubview:aview];
}
(void)imagePickerController:(UIImagePickerController )picker didFinishPickingMediaWithInfo:(NSDictionary )info
{
[SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeBlack];
NSString *videoPath = [NSString stringWithFormat:@”%@”,[info objectForKey:UIImagePickerControllerMediaURL]];
_videoURL = [NSURL URLWithString:videoPath];
NSLog(@”123%@”,_videoURL);
//计算视频文件大小
// NSString *_fileSize = [NSString stringWithFormat:@”%ld kb”, (long)[self getFileSize:[[_videoURL absoluteString] substringFromIndex:16]]];
//计算视频总时长
// NSString *_videoLen = [NSString stringWithFormat:@”%.0f s”, [self getVideoDuration:_videoURL]];
// NSLog(@”视频大小%@,视频长度%@”,_fileSize,_videoLen);
// [self encode];
// NSLog(@”321%@”,_playUrl);
//视频上传
AFHTTPRequestOperationManager *mag = [AFHTTPRequestOperationManager manager];
mag.responseSerializer = [AFHTTPResponseSerializer serializer];
// NSString *url = @”http://192.168.0.115:8081/video/save“;
NSString *url = [NSString stringWithFormat:@”%@video/save”,K_URL];
[mag POST:url parameters:@{@”userPhone”:self.zh} constructingBodyWithBlock:^(id formData) {
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@”成功%@”,responseObject);
NSString *str = @”success”;
flog = [NSString stringWithFormat:@”%@”,str];
NSLog(@”1111%@”,flog);
[SVProgressHUD dismiss];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@”失败%@”,error);
}];
[picker dismissViewControllerAnimated:true completion:^{
}];
}
videoBtn.frame = CGRectMake(20, 20, SCREENWIDTH/3, 40);
[videoBtn setImage:[UIImage imageNamed:@"录制视频.png"] forState:UIControlStateNormal]; [videoBtn addTarget:self action:@selector(getVideoAction:) forControlEvents:UIControlEventTouchUpInside]; [biggerKuang addSubview:videoBtn];
//添加视频模块
- (void)getVideoAction:(UIButton *)sender {
[SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeBlack];
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) { UIImagePickerController* pickerView = [[UIImagePickerController alloc] init]; //UIImagePickerControllerSourceTypePhotoLibrary从手机视频调取,UIImagePickerControllerSourceTypeCamera调用摄像机 pickerView.sourceType = UIImagePickerControllerSourceTypeCamera; //UIImagePickerControllerSourceTypePhotoLibrary 从手机视频调取,UIImagePickerControllerSourceTypeCamera调用摄像机 NSArray* availableMedia = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera]; //availableMedia[0]是照相机 availableMedia[1]摄像机 pickerView.mediaTypes = [NSArray arrayWithObject:availableMedia[1]]; //设置前置摄像头 pickerView.cameraDevice = UIImagePickerControllerCameraDeviceFront; pickerView.videoMaximumDuration = 30; pickerView.delegate = self; [self loadpoetry]; UILabel *head = [[UILabel alloc]initWithFrame:CGRectMake(20, 44, SCREENWIDTH - 40, 50)]; head.text = @"请点击录制视频按钮,并大声朗读以下诗句"; [head setTextColor:[UIColor blueColor]]; [head setTextAlignment:NSTextAlignmentCenter]; head.numberOfLines = 0; [pickerView.view addSubview:head]; aview = [[UILabel alloc]initWithFrame:CGRectMake(10, head.bottom + 5, SCREENWIDTH - 20, 50)];
// aview.text = @”请阅读以下诗歌:锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦!”;
// aview.text = responseObject[@”message”];
[aview setTextColor:[UIColor orangeColor]];
[aview setFont:[UIFont fontWithName:@”Helvetica-Bold” size:18]];
[aview setTextAlignment:NSTextAlignmentCenter];
aview.numberOfLines = 0;
aview.backgroundColor = [UIColor clearColor];
[pickerView.view addSubview:aview];
[self presentViewController:pickerView animated:true completion:^{ }]; } else { UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"没有相机" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; [alert show]; return; }
}
(void)imagePickerController:(UIImagePickerController )picker didFinishPickingMediaWithInfo:(NSDictionary )info
{
[SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeBlack];
NSString *videoPath = [NSString stringWithFormat:@”%@”,[info objectForKey:UIImagePickerControllerMediaURL]];
_videoURL = [NSURL URLWithString:videoPath];
NSLog(@”123%@”,_videoURL);
//计算视频文件大小
// NSString *_fileSize = [NSString stringWithFormat:@”%ld kb”, (long)[self getFileSize:[[_videoURL absoluteString] substringFromIndex:16]]];
//计算视频总时长
// NSString *_videoLen = [NSString stringWithFormat:@”%.0f s”, [self getVideoDuration:_videoURL]];
// NSLog(@”视频大小%@,视频长度%@”,_fileSize,_videoLen);
// [self encode];
// NSLog(@”321%@”,_playUrl);
//视频上传
AFHTTPRequestOperationManager *mag = [AFHTTPRequestOperationManager manager];
mag.responseSerializer = [AFHTTPResponseSerializer serializer];
// NSString *url = @”http://192.168.0.115:8081/video/save“;
NSString *url = [NSString stringWithFormat:@”%@video/save”,K_URL];
[mag POST:url parameters:@{@”userPhone”:self.zh} constructingBodyWithBlock:^(id formData) {
[formData appendPartWithFileURL:_videoURL name:@"video" error:NULL];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@”成功%@”,responseObject);
NSString *str = @”success”;
flog = [NSString stringWithFormat:@”%@”,str];
NSLog(@”1111%@”,flog);
[SVProgressHUD dismiss];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@”失败%@”,error);
}];
[picker dismissViewControllerAnimated:true completion:^{
}];
}
相关文章推荐
- AFNetworking3.0 POST 以二进制的形式传输数据
- HTTP的GET和POST的区别
- 四种常见的 POST 提交数据方式
- HttpPost请求的完美封装
- 本地图片http上传服务器
- angularsjs 对象数组的请求与接收
- 承载网络开启后显示无法连接到Internet,已解决
- WIN8 启用虚拟AP 以共享网络,使手机电脑一起网上冲浪
- Android使用ImageView显示网络图片
- Android中使用HttpClient实现HTTP通信效果
- Android网络通信Volley框架源代码浅析(三)
- (小笔记)popupwindow中listview加载的网络数据有时显示有时不显示
- http用法
- Sheepdog HTTP API
- java 实现 http 文件下载
- App Transport Security has blocked a cleartext HTTP (http://)错误处理
- c# tcp备忘及networkstream.length此流不支持查找解决
- sar分析网卡流量
- .NET - http://referencesource.microsoft.com/
- 通过/proc/net/dev和/proc/net/snmp分析网络包量|流量|错包|丢包以及各网络协议的工作状况