-1

寻找例如带有进度视图的多个视频上传。在这里,我已经定义了步骤。

  1. 打开图库并选择视频。
  2. 从图库中选择视频,并在编译选择后创建拇指图像。
  3. 在表格视图或集合视图中显示带有缩略图的所有选定视频
  4. 在 Tableview 或 Collection 视图中显示视频上传过程的进度。

任何人都知道如何做到这一点,我会对我有所帮助。

可能我们可以使用 NSUrlsession 上传任务但无法实现。

4

1 回答 1

2
  1. 为此,您可以使用MWPhotoBrowser
  2. 您可以使用以下方法生成所选视频的缩略图。

    - (UIImage *)generateThumbImage : (NSString *)filepath {
          NSURL *url = [NSURL fileURLWithPath:filepath];
          AVAsset *asset = [AVAsset assetWithURL:url];
          AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc]initWithAsset:asset];
          imageGenerator.appliesPreferredTrackTransform = YES;
          CMTime time = [asset duration];
          time.value = 2;
          CGImageRef imageRef = [imageGenerator copyCGImageAtTime:time actualTime:NULL error:NULL];
          UIImage *thumbnail = [UIImage imageWithCGImage:imageRef];
          CGImageRelease(imageRef);  // CGImageRef won't be released by ARC
    
          return thumbnail;
    }
    
  3. 为此,您可以检查“MWPhotoBrowser”并将生成的缩略图传递给显示。
  4. 为此,您可以使用AFNetworking 3.0。并创建一个NSObject文件类来管理您的所有文件。创建具有 imageView 和 progressView 的 collectionView。该 collectionView 类型是文件类型。

    @interface File : NSObject
    
    @property (nonatomic, strong) NSString *fullFilePath;
    @property (nonatomic) float overAllProgress;
    - (void)sendFile;
    
    @end
    
    
    @implementation File
    
    - (void)sendFile {
        NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST"            URLString:@"http://localhost/upload.php" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
    
         [formData appendPartWithFileURL:[NSURL fileURLWithPath:self.fullFilePath] name:@"photo_path" fileName:self.relativePath mimeType:@"video/quicktime" error:nil];
    
        } error:nil];
    
        AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
    
        NSURLSessionUploadTask *uploadTask;
        uploadTask = [manager
            uploadTaskWithStreamedRequest:request
            progress:^(NSProgress * _Nonnull uploadProgress) {
          // This is not called back on the main queue.
          // You are responsible for dispatching to the main queue for UI updates
          dispatch_async(dispatch_get_main_queue(), ^{
              //Update the progress view
              self.overAllProgress = uploadProgress.fractionCompleted;
              [[NSNotificationCenter defaultCenter] postNotificationName:@"imageprogress" object:self]
             });
          }
          completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
            if (error) {
               NSLog(@"Error: %@", error);
            } else {
               NSLog(@"%@ %@", response, responseObject);
            }
          }];
    
          [uploadTask resume]; 
    
      @end
    

现在您需要处理文件进度通知。如下所示。

-(void) viewWillAppear:(BOOL)animated{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fileProgress:) name:@"imageprogress" object:nil];
}

- (void)viewDidUnload{
   [super viewDidUnload];
   // Release any retained subviews of the main view.
  [[NSNotificationCenter defaultCenter] removeObserver:self name:@"imageprogress" object:nil];
 }

- (void)fileProgress:(NSNotification *)notif{

      File * info = [notif object];
      if([_arrFiles containsObject:info]){
          NSInteger row = [_arrFiles indexOfObject:info];
          NSIndexPath * indexPath = [NSIndexPath indexPathForRow:row inSection:0];
          UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath];

         [cell.progressView setProgress:info.overAllProgress animated:YES]

       }
}
于 2016-07-25T12:00:03.953 回答