2

I have a very big(>1 gb) encrypted file, When I decrypt it, I get byte array in chunk with method such as

getByteArray(position,size)

Here position determines the position from where the byte array has to be extracted and of which size.

Now I want to play the byte array chunks so received without writing them to a file in storage, I tried CustomMediaDataSource but it is not available below api 23.

I tried converting it to inputstream but it gave me OutOfMemoryException Is there any way to achieve this?

sammalik
  • 83
  • 2
  • 9

1 Answers1

1

1) You need to make sure that your video is formatted/encoded in such a way that it can support streaming. For MP4 video, the moov atom must precede any mdat atoms, but must succeed the ftyp atom.

2) You need to make sure that the encryption being used supports random access to the underlying data. AES/CTR/NoPadding is one example that should work.

3)

a) You can use libmedia (which is non-free), or basically re-implement your own libmedia, creating a local ServerSocket that speaks HTTP to stream the video, and decrypt bytes as needed. This will work with a VideoView or a WebView. If you want to roll your own, you check out http://stackoverflow.com/a/5432091/6585616 for an example of how to create the server.

OR

b) You can use ExoPlayer, and provide it a direct DataSource that handles the decryption on-the-fly. I found some code for an exoplayer implementation supporting such encryption on github -https://github.com/moagrius/EncryptedExoPlayerDemo (MIT License).

Mark
  • 2,362
  • 18
  • 34