I'm downloading and encrypting mp3 files in my android apps. But I'm trying to decrypt and READ the files without writing the file back to file system. When I try to use CipherInputStream to stream the mp3 to android Mediaplayer API, It cannot recognise the file. However, when I try to to convert to Byte array and stream it as ByteArrayInputStream, it works but I don't want to this because it could take much time for larger files and store the data in JVM.
Here is my code
FileInputStream fis = new FileInputStream(file);
CipherInputStream cis = new CipherInputStream(fis, cipher);
mbuffer = new ByteArrayInputStream(getByte(cis));
Response streamResponse = new Response(Status.OK, mimeType, mbuffer);
The above code works fine but the problem with this
new ByteArrayInputStream(getByte(cis));
in getByte
method, I convert CipherInputStream
to byte then convert it back to InputStream
.
I'm trying to stream cis directly to
Response streamResponse = new Response(Status.OK, mimeType, cis);
But doesn't work with 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();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.