How to play video from a Byte array?

I am working on an application that requires encryption of video files, which works quite well. But the method that I use for decryption returns the video, as in an array of bytes. Anyway, I can play the video using this array without creating a new file.

Decoding of my method:

private static byte[] decrypt(byte[] raw, byte[] encrypted) throws EncrypterException { SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); try { final Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, skeySpec); return cipher.doFinal(encrypted); } catch (Exception e) { throw new EncrypterException(e); } } 

Please help me, am I stuck here?

+6
source share
3 answers

How do you usually play the video? You send an instance of InputStrem to the player. So you are a ByteArrayInputStream that wraps your byte array and sends it to the player.

+1
source

After many searches, this answer can be summarized. All loans must be made by decision owners.

Since VideoView accepts only a URL or file, we have two solutions:

Decision 1; Create a temp file with a stream and provide this file in videoView.

Link; fooobar.com/questions/809393 / ...

Decision 2; Create a media server on your local Android system and stream to the media server where the videoView is directed to the local host for streaming.

Link; fooobar.com/questions/61648 / ...

Other Ref; Which is very useful thanks to freedom; fooobar.com/questions/418577 / ...

+1
source

You should not serve a VideoView with a static file, but with a stream. How to create this thread? Refer to supported Android multimedia formats . The simplest can be a local HTTP server. LocalSingleHttpServer is an example of a library component that implements such a solution.

0
source

Source: https://habr.com/ru/post/909609/


All Articles