8

I am using ExoPlayer to play Media files(mp4s .h264 encoded) from the SD card of a device. Some of the files are DES encrypted. I can decrypt the files and get back an inputStream, but then I am unsure of how to play this inputStream using ExoPlayer. Any help would be appreciated.

protected void playVideo(File file) {
        InputStream is;
        if (file.getName().endsWith(".DES")) {
            is = FileManager.decryptFile(file);
            //what to do with this input stream?
        }

        Uri uri = Uri.parse(file.getAbsolutePath());

        if (mPlayer != null) {
            mPlayer.release();
        }

        mPlayer = new VideoPlayer(getRendererBuilder(uri));
        mPlayer.addListener(this);
        if (mLastPosition > 0) {
            mPlayer.seekTo(mLastPosition);
        }

        mPlayer.prepare();
        mPlayer.setSurface(mSurface);
        mPlayer.setPlayWhenReady(true);
    }
Adam W
  • 972
  • 9
  • 18
  • InputStream should be written into a temporary file, which will be actually played by ExoPlayer. I am trying the same thing, but the problem is that it takes a lot of time to decryptFile. Did you found a solution for passing InputStream itself to Exo? – Eu Vid Sep 18 '15 at 09:51
  • I never did find a solution to this. We implemented encryption on the whole SD card when it is mounted/unmounted using encfs. I still would like to figure this out because I believe it is part of a better solution but haven't had time to really delve further into it. – Adam W Sep 18 '15 at 16:21

1 Answers1

1

You can write a custom DataSource that accepts an InputStream: for DataSource, you just implement open(DataSpec), close(), and read(byte[] buffer, int offset, int readLength). What astonishes me is that there doesn't seem to be any implementation already available in ExoPlayer. It would seem like an obvious blade for their swiss army knife.

Mike Sokolov
  • 6,914
  • 2
  • 23
  • 31
  • There was implementation, but they hided it https://github.com/google/ExoPlayer/blob/master/library/src/main/java/com/google/android/exoplayer/hls/Aes128DataSource.java – Roger Alien Jun 02 '16 at 23:53
  • @RogerAlien link broken – Adam W Aug 01 '16 at 15:45
  • 1
    @AdamW https://gist.github.com/AlienAsRoger/a0011d246d83c3823d73fcc5bb6a44d6 http://www.programcreek.com/java-api-examples/index.php?source_dir=ExoPlayer-master/library/src/main/java/com/google/android/exoplayer/hls/Aes128DataSource.java – Roger Alien Aug 01 '16 at 22:48