Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to save downloaded files in cache android

Tags:

android

Hi i'm streaming video from a website in my android application. I have a history option showing the last seen videos. I wonder if i can use cache so that when the user enters the history the video is played faster (not downloaded again). When you use cache in Android does that mean that the whole video is downloaded and saved somewhere? or some data is saved somwhere(not the whole video).

Some help will be appreciated!!!

Thanks.

like image 554
madcoderz Avatar asked Jan 14 '11 10:01

madcoderz


1 Answers

It should help you.

    URLConnection cn = new URL(mediaUrl).openConnection();   
    cn.connect();   
    InputStream stream = cn.getInputStream();

    File downloadingMediaFile = new File(context.getCacheDir(), "downloadingMedia.dat");

    FileOutputStream out = new FileOutputStream(downloadingMediaFile);   
    byte buf[] = new byte[16384];
    do {
        int numread = stream.read(buf);   
        if (numread <= 0) break;   
        out.write(buf, 0, numread);
        // ... 
    } while (...);
like image 134
gulbrandr Avatar answered Sep 28 '22 06:09

gulbrandr