简体   繁体   中英

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 . 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. 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 . 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 ?

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.

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. 2. Implement custom data source classes and implement, intercept the calls and modify the request/response objects as per your need.

I have faced similar issue but in my case i have a custom scheme instead of http. Default OkHttpDataSource does not handle custom url schemes hence i had to write my own data source and intercept.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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