[英]Decrypt and read mp3 file directly from CipherInputStream without storing
我正在Android應用程序中下載和加密mp3文件。 但是我試圖解密和讀取文件,而不將文件寫回到文件系統。 當我嘗試使用CipherInputStream將mp3流傳輸到android Mediaplayer API時,它無法識別該文件。 但是,當我嘗試轉換為Byte數組並將其作為ByteArrayInputStream進行流傳輸時,它可以工作,但是我不想這樣做,因為較大的文件和將數據存儲在JVM中可能會花費很多時間。
這是我的代碼
FileInputStream fis = new FileInputStream(file);
CipherInputStream cis = new CipherInputStream(fis, cipher);
mbuffer = new ByteArrayInputStream(getByte(cis));
Response streamResponse = new Response(Status.OK, mimeType, mbuffer);
上面的代碼工作正常,但與此有關的問題
new ByteArrayInputStream(getByte(cis));
在getByte
方法中,我將CipherInputStream
轉換為byte,然后將其轉換回InputStream
。
我正在嘗試直接將順式流式
Response streamResponse = new Response(Status.OK, mimeType, cis);
但不適用於MediaPlayer
File tempMp3 = File.createTempFile("kurchina", "mp3", getCacheDir());
tempMp3.deleteOnExit();
FileOutputStream fos = new FileOutputStream(tempMp3);
fos.write(mp3SoundByteArray);
fos.close();
FileInputStream fis = new FileInputStream(tempMp3);
mp.setDataSource(fis.getFD());
mp.prepare();
mp.start();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.