Thread: How to get remaining time in downloading

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    113

    How to get remaining time in downloading

    Hi,

    I am developing a application in which songs are download from the server.
    I am able to download it but the problem is that I am not able to get the remaining time while the song is downloading......like 2 min remaining ....
    How can I do this ???

    Thanks

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You need to know the full size of the file. If you know that, then you take a measurement of how far you have got so far, and the time it's taken so far. Divide the time taken so far by the proportion done (always less than one, so you should get a bigger value), and display that as "time remaining".

    So, if we have a 4MB file, we've got 1.2MB so far in 10 seconds:
    Code:
    totalSize = 4 * 1024 * 1024;
    doneSize = (int)(1.2 * 1024 * 1024); 
    timeUsed = 10;
    timeRemaining = timeUsed * ((double)doneSize / totalSize);
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers
    By Big_0_72 in forum C Programming
    Replies: 3
    Last Post: 10-28-2008, 07:51 PM
  2. Determine the closest departure time
    By Kyeong in forum C Programming
    Replies: 9
    Last Post: 10-07-2008, 08:06 PM
  3. Scheduling
    By Jules in forum Tech Board
    Replies: 4
    Last Post: 01-18-2004, 01:47 PM
  4. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 06:00 PM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM