繁体   English   中英

直接从CipherInputStream解密和读取mp3文件,而无需存储

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM