-1

Looking for example for multiple video upload with progress view . Here i have defined steps.

  1. Open gallery and select video.
  2. select video from gallery and after compilation of selection ,create thumb image.
  3. All selected video show with thumb images in tableview or collection view
  4. showing video uploading process in Tableview or Collection view with progress .

Any one know how to do that, i would be helpful for me .

May be we can use NSUrlsession UPload task but not able to implement.

Darshan
  • 2,272
  • 3
  • 31
  • 43

1 Answers1

2
  1. For this You can use MWPhotoBrowser
  2. You can use below method to generate thumb image of selected video.

    - (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. For this you can check "MWPhotoBrowser" and pass generated thumb image to display.
  4. For this you can use AFNetworking 3.0. And create one NSObject file class that manage all your file. Create collectionView that has imageView and progressView. That collectionView type is file type.

    @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
    

Now you need to handle file progress notification. Like below.

-(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]

       }
}
Ekta Padaliya
  • 5,743
  • 3
  • 39
  • 51
  • Hi ekta do u have any Sample App regarding Multiple video upload with progress. – Darshan Jul 25 '16 at 12:04
  • No I don't have it r8 now. But you can follow this step. Hope it will help and you can understand how it works. If you have any question then please ask. – Ekta Padaliya Jul 25 '16 at 12:07
  • Mention not. Just give upvote and accept if you feel that its helpful. That's the motivation for me. :D – Ekta Padaliya Jul 25 '16 at 12:09