Online encrypted streaming video files with AES in exoplayer android

I have AES encrypted video files stored on the server. How to broadcast them online in exoplanet? I do not want to download the file and decrypt it: waiting for the download to complete and then playing the decrypted file.

+4
source share
1 answer

I would suggest taking a look at the UriDataSourceor interface DataSource. You can get from DataSourceand provide an implementation very similar to UriDataSource, and pass it to ExoPlayer. This class has access to the method read()through which all bytes pass. This method allows you to decrypt files on the fly one buffer at a time.

In ExoPlayer 2.0, you provide your own of DataSourceyour own DataSource.Factory, which you can transfer to ExtractorMediaSource(or any other MediaSource).

ExoPlayer 2.0, DataSource ExtractorSampleSource, VideoRenderer AudioRender buildRenderers() RendererBuilder, . ( " " Google ", , , , - , - ).

read():

@Override
public int read(byte[] buffer, int offset, int readLength) throws IOException {
    if (bytesRemaining == 0) {
        return -1;
    } else {
        int bytesRead = 0;
        try {
            long filePointer = randomAccessFile.getFilePointer();
            bytesRead =
                    randomAccessFile.read(buffer, offset, (int) Math.min(bytesRemaining, readLength));
            // Supply your decrypting logic here
            AesEncrypter.decrypt(buffer, offset, bytesRead, filePointer);
        } catch (EOFException eof) {
            Log.v("Woo", "End of randomAccessFile reached.");
        }

        if (bytesRead > 0) {
            bytesRemaining -= bytesRead;
            if (listener != null) {
                listener.onBytesTransferred(bytesRead);
            }
        }
        return bytesRead;
    }
}

[EDIT] SO post, .

+1

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


All Articles