在exoplayer android中使用AES在线加密的流视频文件 [英] Online encrypted streaming video files with AES in exoplayer android
问题描述
我将用AES加密的视频文件存储在服务器上.如何在exoplayer中在线播放它们?我不想下载文件并对其解密:等待下载完成然后播放解密的文件.
I have video files encrypted with AES stored on server. How to stream them online in exoplayer? I don't want to download the file and decrypt it: waiting for the download to complete and then play decrypted file.
推荐答案
我建议您看一下UriDataSource
或DataSource
界面.您可以从DataSource
派生并提供与UriDataSource
非常相似的实现,并将其传递给ExoPlayer.该类可以访问所有字节均通过的read()
方法.该方法使您可以一次解密一个缓冲区中的文件.
I would suggest taking a look at the UriDataSource
or the DataSource
interface. You can derive from DataSource
and provide an implementation very similar to UriDataSource
and pass that into ExoPlayer. That class has access to the read()
method which all the bytes pass through. That method allows you to decrypt the files on the fly one buffer at a time.
在ExoPlayer 2.0中,您可以从自己的自定义DataSource.Factory
中提供自己的自定义DataSource
,该自定义DataSource
可以传递给ExtractorMediaSource
(或任何其他MediaSource
).
In ExoPlayer 2.0, you supply your own custom DataSource
from your own custom DataSource.Factory
which can be passed to an ExtractorMediaSource
(or any other MediaSource
).
如果您未使用ExoPlayer 2.0,则将DataSource
传递给ExtractorSampleSource
,然后传递给实现的自定义RendererBuilder
的buildRenderers()
中的VideoRenderer
和AudioRender
.
(此外,您也可以使用Google自定义数据源exoplayer",如果我提供的内容不够,那应该可以提供更多信息-或者我可以澄清您是否找不到任何东西.)
If you're not on ExoPlayer 2.0, you pass the DataSource
to the ExtractorSampleSource
and then to the VideoRenderer
and the AudioRender
in the buildRenderers()
of a custom RendererBuilder
that you implement.
(Also you can Google "custom datasource exoplayer" and that should give more info if what I provided isn't enough - or I can clarify if you can't find anything).
这是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;
}
}
也刚刚发现这篇SO帖子,其中有类似的建议.
Also just found this SO post which has a similar suggestion.
这篇关于在exoplayer android中使用AES在线加密的流视频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!