开发者

how to save downloaded files in cache 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开发者_如何学C 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.


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 (...);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜