我正在尝试使用Exoplayer 2.7.3播放HLS媒体播放列表。 清单的网址(m3u8文件)是从一台服务器(Akamaihd.net)请求的,但是解密TS文件的密钥是从另一台服务器(mediaset.es)获得的,该服务器需要他自己的标头(包括cookie),与获取m3u8文件所需的标头。情况是:
m3u8文件的网址为:
https://mdslivehlsb-i.akamaihd.net/hls/live/623617/energy/bitrate_4.m3u8
获取此m3u8文件的http标头为:
. Accept: */*
. Accept-Encoding: gzip, deflate, br
. Connection: keep-alive
. Cookie: _alid_=JI5fkmR9nXtRAn/z+dOR/Q==; hdntl=exp=1545916363~acl=%2fhls%2flive%2f623617%2fenergy%2f*~data=hdntl~hmac=f12cff2e63f5277b642da3e2f5c041110f379b19db2994cbb7af815179f3462b; removed_hdnts=st=1545829964~exp=1545829971~acl=/hls/live/623617/energy/*~hmac=843c426ae453a991274cb4b51904c7c05fbb057638c1447717d67fe199b212c2
. Host: mdslivehlsb-i.akamaihd.net
. Origin: https://www.mitele.es
http响应为:
#EXTM3U
#EXT-X-TARGETDURATION:10
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:154582991
#EXT-X-KEY:METHOD=AES-128,URI="https://gatekeeper.mediaset.es/key/energy/akamai",IV=0x88888000000000000000000000000000
#EXT-X-PROGRAM-DATE-TIME:2018-12-26T14:11:42.000+0100
#EXTINF:10,
0/br1/181205091606/85880/154582991.ts
…..
因此必须从以下位置获取密钥:
https://gatekeeper.mediaset.es/key/energy/akamai
还需要其他http标头:
authority: gatekeeper.mediaset.es
accept-language: es-ES,es;q=0.9
cookie: gtk=54a1565d55aaf9b18f7e417036
origin: https://www.mitele.es
Referer: https://www.mitele.es/live/index.html?alias=energy
使用“ getDefaultRequestProperties()”,将标头设置为akamaidh服务器以获取m3u8文件:
private MediaSource buildMediaSourceHlsMedia(Uri uri) throws MalformedURLException {
MediaSource ms;
int minLoadableRetryCount;
String UserAgent = UserAgentDefinido(uri);
CustomHttpDataSourceFactoryMitele factory = new CustomHttpDataSourceFactoryMitele(UserAgent, null, DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS, true, null);
// here I set the akamaihd headers:
dataSourceWithHeadersMitele(factory, uri.toString());
ms = new HlsMediaSource.Factory(factory).setMinLoadableRetryCount(5).createMediaSource(uri);
return ms;
}
private void dataSourceWithHeadersMitele(CustomHttpDataSourceFactoryMitele datasourceOriginal, String urifinal) throws MalformedURLException {
URL url = new URL(urifinal);
datasourceOriginal.getDefaultRequestProperties().set("Host", url.getHost());
datasourceOriginal.getDefaultRequestProperties().set("Accept", "*/*");
datasourceOriginal.getDefaultRequestProperties().set("Accept-Language", "es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3");
datasourceOriginal.getDefaultRequestProperties().set("Accept-Encoding", "gzip, deflate, br");
datasourceOriginal.getDefaultRequestProperties().set("Referer", "https://www.mitele.es/live/index.html?alias=energy");
datasourceOriginal.getDefaultRequestProperties().set("Origin", "https://www.mitele.es");
datasourceOriginal.getDefaultRequestProperties().set("Connection", "keep-alive");
datasourceOriginal.getDefaultRequestProperties().set("Cookie", mCookies);
datasourceOriginal.getDefaultRequestProperties().set("Pragma", "no-cache");
datasourceOriginal.getDefaultRequestProperties().set("Cache-Control", "no-cache");
}
如何以及在何处设置向第二台服务器请求解密密钥所需的http标头?
预先感谢