如何在将视频文件从服务器下载到iphone时显示进度条? [英] how to display progressbar during downloading video file from the server in to the iphone?

查看:487
本文介绍了如何在将视频文件从服务器下载到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.

这篇关于如何在将视频文件从服务器下载到iphone时显示进度条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆