0

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?

4

3 回答 3

4

您可以为此设置图像选择器的 videoMaximumDuration 属性。

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    imagePicker.mediaTypes  = @[(NSString *)kUTTypeMovie];
    imagePicker.videoQuality = UIImagePickerControllerQualityTypeHigh;
    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;


    imagePicker.videoMaximumDuration = 10;
于 2013-05-06T07:16:04.487 回答
0

您可以使用此获取视频的持续时间

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]); 
}
于 2013-05-06T07:15:33.030 回答
0

尝试这个

   - (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;
     }
于 2013-05-06T08:04:07.063 回答