SciLor's Open Source Forums

Also visit my Website!
It is currently Wed Sep 19, 2018 5:18 pm

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Mon Sep 13, 2010 6:34 am 
I was wondering how you got the size of the file you are downloading, and thus were allowed to do the progress bar
I've got the song successfully downloaded, just can't seem to find out how to get the size of the song
Here is a small piece of code that does the writing to the mp3 file
(fs is the filestream, and buffer was created before)

Thanks for any help, couldn't have gotten to where I am with out many of the small snippets posted on the site in various places

Code:
            Stream stream = response.GetResponseStream();
           

            int count = 0;
            do
            {
                count = stream.Read(buffer, 0, buffer.Length);
                if (count > 0)
                {
                    fs.Write(buffer, 0, count);
                }
            } while (count > 0);




EDIT: I attempted to use Length instead of ContentLength on the responsestream, stupid me!!


Top
  
 
 
Online
The Adswinger

Joined: Wed Jan 13, 2010 11:56 pm
Posts: Too many!
Donated: Ad Posts


PostPosted: Mon Sep 13, 2010 4:30 pm 
Offline
The Developer

Joined: Wed Jan 13, 2010 11:56 pm
Posts: 1467
Donated: free software
Yeah, ContentLength gives you all that is needed!

_________________
My Windows Mobile and Windows Open Source Website:
www.scilor.com

Like my work? Donate!
Donation Website

My Programs:
grooveshark™.com Downloader, GrooveMobile, Fuel Blaster, Chameleon TicTacToe, QuickTap, WiMoBlue, Driving Licence Trainer, CodeSnippetViewer, Gesture Launcher, Fahrplanauskunft, GSensor Control


Top
 Profile  
 
PostPosted: Mon Sep 13, 2010 10:32 pm 
I guess I'll post the solution in case others read this

Code:
long clength =response.ContentLength;

            Stream stream = response.GetResponseStream();
           

            int count = 0;
            long dw = 0;
            do
            {
                count = stream.Read(buffer, 0, buffer.Length);
                dw += count;
                Console.WriteLine("Dw: {0} CLength:{1} = {2}", dw, clength, (dw * 100 / clength));
                if (count > 0)
                {
                    os.Write(buffer, 0, count);
                }
            } while (count > 0);


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
template->_php_include(): File ./counter/foruminclude.php does not exist or is empty Powered by phpBB® Forum Software © phpBB Group