【问题标题】:Capture a video of 10 seconds length and upload it to server using ASIHTTPRequest捕获 10 秒长的视频并使用 ASIHTTPRequest 将其上传到服务器
【发布时间】:2013-05-06 07:05:07
【问题描述】:

我需要捕获一个最长为 10 秒的视频,并且还需要使用 ASIHttpRequest 将其上传到服务器,

我该怎么做?

【问题讨论】:

  • Please note that I am no longer working on this library - you may want to consider using something else for new projects. :) - 写于allseeing-i.com/ASIHTTPRequest

标签: iphone video asihttprequest video-capture


【解决方案1】:

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

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


    imagePicker.videoMaximumDuration = 10;

【讨论】:

    【解决方案2】:

    你可以通过这个来获取视频的时长

    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]); 
    }
    

    【讨论】:

      【解决方案3】:

      试试这个

         - (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;
           }
      

      【讨论】:

      • 您是否会考虑添加一些叙述来解释此代码为何有效,以及是什么使它成为问题的答案?这对提出问题的人以及其他任何出现的人都非常有帮助。
      猜你喜欢
      • 2014-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-12
      • 2019-02-08
      • 2012-03-01
      相关资源
      最近更新 更多