简体   繁体   English

在 android ExoPlayer 中添加播放加密 .m3u8 流的参数

[英]Adding parameters for playing encrypted .m3u8 stream in android ExoPlayer

I have some encrypted (AES-128) .m3u8 stream in my Android app and I want to play it in ExoPlayer .我的Android应用程序中有一些加密的 (AES-128) .m3u8流,我想在ExoPlayer播放它。 I have for this two variables:我有这两个变量:

val secretKey = "a4cd9995a1aa91e1"
val initVector = "0000000000000000"

As I read in docs I need to add URI and IV parameters into source file.当我在文档中阅读时,我需要将URIIV参数添加到源文件中。 After adding I have the next one:添加后我有下一个:

    #EXTM3U
    #EXT-X-VERSION:3
    #EXT-X-TARGETDURATION:6
    #EXT-X-MEDIA-SEQUENCE:0
    #EXT-X-DISCONTINUITY
    #EXT-X-KEY:METHOD=AES-128,URI="data:text/plain;charset=utf-8,a4cd9995a1aa91e1",IV=0x30303030303030303030303030303030
    #EXTINF:6.0,
    media_b525000_0.ts
    #EXTINF:6.0,
    media_b525000_1.ts
    #EXTINF:6.0,
    media_b525000_2.ts
    *other .ts segments...*

where I added two lines: #EXT-X-DISCONTINUITY and #EXT-X-KEY .我在其中添加了两行: #EXT-X-DISCONTINUITY#EXT-X-KEY But the player doesnt play the stream and I have the next exception:但播放器不播放流,我有下一个例外:

com.google.android.exoplayer2.upstream.HttpDataSource$HttpDataSourceException: Malformed URL

What did I do wrong?我做错了什么? And how can I to decrypt stream when I have secretKey and initVector ?而且我怎么能解密流时,我有secretKeyinitVector

Exoplayer assumes anything following URI is an actual URL in m3u8 file and when it tries to load the encryption key using the below url which is invalid, above exception is thrown by OkHttpDataSource class. Exoplayer 假设 URI 之后的任何内容都是 m3u8 文件中的实际 URL,当它尝试使用以下无效 url 加载加密密钥时,OkHttpDataSource 类会抛出上述异常。

URI="data:text/plain;charset=utf-8,a4cd9995a1aa91e1"

This problem can be solved in two ways.这个问题可以通过两种方式解决。 1. Place the encryption key in a server and use a URL to fetch it. 1. 将加密密钥放在服务器中并使用 URL 获取它。 2. Implement custom data source classes and implement, intercept the calls and modify the request/response objects as per your need. 2. 实现自定义数据源类并根据需要实现、拦截调用并修改请求/响应对象。

I have faced similar issue but in my case i have a custom scheme instead of http.我遇到了类似的问题,但就我而言,我有一个自定义方案而不是 http。 Default OkHttpDataSource does not handle custom url schemes hence i had to write my own data source and intercept.默认 OkHttpDataSource 不处理自定义 url 方案,因此我必须编写自己的数据源并进行拦截。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM