How to play encrypted file in Android

I need to be able to play an encrypted file in Android.

AAC file.

The only way I can do this is either:

  • decrypt the file in the internal private storage and specify the player in this file to play or
  • decrypt and decode the file to pcm and transfer it to AudioTrack.

1 is not great because it takes a lot of time.
2 is not very good, because I do not know how I can use an HW decoder for this.

Any ideas?

TIA.

+4
source share
2 answers

If you have an encryption format that can be decrypted in a stream, you can insert a proxy server between the stream source and the media player and read it from there.

The NPR Android News application shows an example of a proxy server that allows devices with pre-installation 2.2 to correctly handle Shoutcast streams. See the StreamProxy class in the source code for how this is done, and lines 410 -418 (as of the last update) of the PlaybackService class to implement this. Essentially, he simply changed the URL to run through the local proxy:

if (stream && Build.VERSION.SDK_INT < 8) { if (proxy == null) { proxy = new StreamProxy(); proxy.init(); proxy.start(); } playUrl = String.format("http://127.0.0.1:%d/%s", proxy.getPort(), url); } 

If your stream comes from a local file, and not from the Internet, you can do something like HttpRawResourceServer , which I wrote as a test harness for connecting to media players.

+4
source

Well, I think Android does not support .AAC format.

  3GPP (.3gp) and MPEG-4 (.mp4, .m4a). No support for raw AAC (.aac) 

but you can change the playerdriver.cpp file in Android OpenCORE with the following line:

 mDataSource->SetDataSourceFormatType(PVMF_FORMAT_UNKNOWN); 

to

 mDataSource->SetDataSourceFormatType(PVMF_AACFF); 

then you can play your AAC file =)

0
source

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


All Articles