如何在将视频文件从服务器下载到iphone时显示进度条?

问题描述:

我在iphone中实现了视频播放功能。我从服务器下载视频文件,然后播放。
但是我想在下载视频文件时显示进度条。对于进度条我需要计算时间我不知道如何计算下载视频需要多长时间。

I have implemented video play functionality in iphone.In which i am downloading video file from the server and then play. But I want to display progress bar during downloading video file.For progressbar i need to calculate timing i don't know how to calculate time how much will take time for downloading video.

所以请帮我解决这个问题。

So please help me for this query.

提前致谢。

您可以在NSURLConnection的 NSURLConnectionDataDelegate 的以下回调方法中获得预期的总文件大小:

You can get the expected total file size in the following callback method of NSURLConnection's NSURLConnectionDataDelegate:

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
   self.expectedTotalSize = response.expectedContentLength;
}

然后在下面的回调方法中,您可以计算收到的数据量: / p>

then in following callback method you can calculate how much data has been received:

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
   self.recievedData += data.length;
}

您可以使用UIProgressView在屏幕上显示当前的下载状态。

And you can use UIProgressView to show current downloading status on the screen.