I need to capture a video which will be maximum length of 10 seconds, and also need to upload it to server using ASIHttpRequest
,
how do I do that?
I need to capture a video which will be maximum length of 10 seconds, and also need to upload it to server using ASIHttpRequest
,
how do I do that?
您可以为此设置图像选择器的 videoMaximumDuration 属性。
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.mediaTypes = @[(NSString *)kUTTypeMovie];
imagePicker.videoQuality = UIImagePickerControllerQualityTypeHigh;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.videoMaximumDuration = 10;
您可以使用此获取视频的持续时间
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:selectedVideoUrl];
CMTime duration = playerItem.duration;
float seconds = CMTimeGetSeconds(duration);
NSLog(@"duration: %.2f", seconds);
您可以使用将其上传到服务器
//server url to upload
NSURL *url = [NSURL URLWithString: URL];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setUseKeychainPersistence:YES];
//give your file path here and key
[request addFile:file_path forKey:@""];
[request setDelegate:self];
[request setDidFinishSelector:@selector(uploadRequestFinished:)];
[request setDidFailSelector:@selector(uploadRequestFailed:)];
[request startAsynchronous];
//successful uploaded
- (void)uploadRequestFinished:(ASIHTTPRequest *)request{
}
//when failed
- (void)uploadRequestFailed:(ASIHTTPRequest *)request{
NSLog(@" Error - Statistics file upload failed: \"%@\"",[[request error] localizedDescription]);
}
尝试这个
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)mediaDict {
NSString *type = [mediaDict objectForKey:UIImagePickerControllerMediaType];
if ([type isEqualToString:(NSString *)kUTTypeVideo] ||
[type isEqualToString:(NSString *)kUTTypeMovie]) { // movie != video
NSURL *url = [mediaDict objectForKey:UIImagePickerControllerMediaURL];
NSData *data = [NSData dataWithContentsOfURL:videoURL];
// UPLOAD THIS DATA because you must convert video file to NSData. and must take Post method.
}
return nil;
}