Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 直接从CipherInputStream解密和读取mp3文件,无需存储_Java_Android_Encryption_Mp3 - Fatal编程技术网

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

Java 直接从CipherInputStream解密和读取mp3文件,无需存储,java,android,encryption,mp3,Java,Android,Encryption,Mp3,我正在android应用程序中下载并加密mp3文件。但我正在尝试解密和读取文件,而不将文件写回文件系统。当我尝试使用CipherInputStream将mp3流式传输到android Mediaplayer API时,它无法识别该文件。但是,当我尝试转换为字节数组并将其作为ByteArrayInputStream流传输时,它可以工作,但我不想这样做,因为对于较大的文件和在JVM中存储数据可能需要很多时间 这是我的密码 FileInputStream fis = new FileInputStre

我正在android应用程序中下载并加密mp3文件。但我正在尝试解密和读取文件,而不将文件写回文件系统。当我尝试使用CipherInputStream将mp3流式传输到android Mediaplayer API时,它无法识别该文件。但是,当我尝试转换为字节数组并将其作为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
方法中,我将
cipheriputstream
转换为byte,然后将其转换回
InputStream

我正在尝试将CI直接流式传输到

Response streamResponse = new Response(Status.OK, mimeType, cis);

但是不适用于MediaPlayer

您能否提供更多关于它如何“不适用于”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();