2013-06-11 26 views
0

我的Android應用程序從服務器下載一堆照片和視頻,我想緩存這些數據。我已經使用DiskLruCach庫緩存圖像,它工作正常,但現在我想緩存視頻也。DiskLruCache視頻

我已經試過這樣的事情,但它似乎沒有工作 - 我無法找到在緩存目錄中的視頻東西:

private boolean writeVideoToFile(String videoUri, DiskLruCache.Editor editor) throws IOException, FileNotFoundException { 
    OutputStream out = null; 
    FileOutputStream fos; 
    try { 
     out = new BufferedOutputStream(editor.newOutputStream(0), Utils.IO_BUFFER_SIZE); 
     File videoFile = Utils.createFile(Utils.TYPE_VIDEO_FILE); 
     fos = new FileOutputStream(videoFile); 
     fos.write(videoUri.getBytes()); 
     fos.close(); 
     return true; 
    } finally { 
     if (out != null) { 
      out.close(); 
     } 
    } 
} 

誰能給我如何我的IDEEA可以做到這一點?

回答

1

沒有足夠的信息,但我想調用getBytes()是問題,可能是OutOfMemory異常。

不要將整個視頻文件讀入內存(調用getBytes)。相反,使用一個小的中間緩衝區,通過塊寫入/緩存視頻文件塊。

0

你在致電getBytes()字符串 videoUri。 這真的是你的意思嗎?

+0

我已經放棄了這段代碼!現在我正在使用一個簡單的DiskLruCache實現。它適用於位圖,但我遇到了視頻部分的問題。請參閱此鏈接 - http://stackoverflow.com/questions/17382065/simplediskcache-inputstream-bad-number-format如果您有任何ideea,請分享!謝謝! – Alin