0

In my iOS app i am downloading a youtube video files to the iPhone using following code

LBYouTubeExtractor *extractor = [[[LBYouTubeExtractor alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:(@"http://www.youtube.com/watch?v=%@"), videoURL ]] quality:LBYouTubeVideoQualityLarge] autorelease];

   [extractor extractVideoURLWithCompletionBlock:^(NSURL *videoURLL, NSError *error) {
        if(!error) {   

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                NSData *videoData = [NSData dataWithContentsOfURL:videoURLL ];
                NSString *pathToDocs = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
                NSString *filename = [NSString stringWithFormat:(@"video_%@.mp4"),videoURL];

                [videoData writeToFile:[pathToDocs stringByAppendingPathComponent:filename ] atomically:YES];

            });


 } else {
            NSLog(@"Failed extracting video URL using block due to error:%@", error);
        }
    }];

I want to show download progress in my app. How should i calculate the file size and percentage downloaded.

Susitha
  • 3,339
  • 5
  • 27
  • 41

1 Answers1

0

Declare bytesDownloaded and downloadSize as a float. If they are int you will need to cast them to a floating point value.

long double precent = (bytesDownloaded/downloadSize) * 100.0;
Göktuğ Aral
  • 1,409
  • 1
  • 13
  • 28