保存视频在文档目录中时剩余的字节数

时间:2014-08-01 16:36:41

标签: ios objective-c video download

我正在将视频从URL下载到文档目录。视频没有固定的大小。如何显示用户的下载状态。有没有办法显示要下载的剩余字节?

这是我的代码 -

       dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
       NSString *urlToDownload = @"http://someurl.mp4";
       NSURL  *url = [NSURL URLWithString:urlToDownload];
       NSData *urlData = [NSData dataWithContentsOfURL:url];
        if ( urlData )
        {
            NSArray       *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString  *documentsDirectory = [paths objectAtIndex:0];
            NSString  *filePath = [NSString stringWithFormat:@"%@/%@.mp4", documentsDirectory,[[[array objectAtIndex:i] objectForKey:@"name"]stringByReplacingOccurrencesOfString:@" " withString:@"_"]];


            //saving is done on main thread
            dispatch_async(dispatch_get_main_queue(), ^{
                [urlData writeToFile:filePath atomically:YES];
                NSLog(@"File Saved -------- %@!",filePath);

            });
             }
             }
          });

1 个答案:

答案 0 :(得分:0)