我有一个托管在服务器上的 HLS m3u8 播放列表:
#EXTM3U
#EXT-X-TARGETDURATION:10
#EXT-X-ALLOW-CACHE:YES
#EXT-X-KEY:METHOD=AES-128,URI="https://myserver/playlist/336385.smil/crypt.key?e=6889c9ad1087852"
#EXT-X-VERSION:2
#EXT-X-MEDIA-SEQUENCE:1
#EXTINF:10,
http://myserver/playlist/336385.smil/segment1_3_av.ts?e=6889c9ad1087852b
#EXTINF:10,
http://myserver/playlist/336385.smil/segment2_3_av.ts?e=6889c9ad1087852b
#EXTINF:10,
http://myserver/playlist/336385.smil/segment3_3_av.ts?e=6889c9ad1087852b
#EXTINF:10,
http://myserver/playlist/336385.smil/segment4_3_av.ts?e=6889c9ad1087852b
#EXTINF:10,
http://myserver/playlist/336385.smil/segment5_3_av.ts?e=6889c9ad1087852b
#EXTINF:10,
http://myserver/playlist/336385.smil/segment6_3_av.ts?e=6889c9ad1087852b
#EXT-X-ENDLIST
但是检索播放列表需要额外的 url 参数,即调用将如下所示:
http://myserver/playlist/336385.smil/segment1_3_av.ts?e=6889c9ad1087852b¶m1=value1¶m2=value2
将标题设置为setDataSource(上下文上下文,Uri uri,地图标题)上的键值对不起作用,至少我尝试的方式是这样。以下是我从原始 url 参数创建标题的方法:
String paramString =playlistUrl.substring( playlistUrl.indexOf("?") + 1);
String paramsSplit[] = paramString.split("&");
HashMap<String, String> headers = new HashMap<String, String>();
for(int i= 0;i<paramsSplit.length;i++)
{
String key = paramsSplit[i].substring(0, playlistUrl.indexOf("="));
String value = paramsSplit[i].substring(playlistUrl.indexOf("=")+1, playlistUrl.length() );
headers.put(key, value);//e.g headers.put("param1", "value1");
}
因此,我最终得到了一个包含我的参数的 Map(即 Map'<'param, value'>'),但添加这些标题不起作用。
如果我通过播放列表 m3u8 本身并使用最后的额外参数修改每个单独的 url 调用,则播放列表如下:
#EXTM3U
#EXT-X-TARGETDURATION:10
#EXT-X-ALLOW-CACHE:YES
#EXT-X-KEY:METHOD=AES-128,URI="https://myserver/playlist/336385.smil/crypt.key?e=6889c9ad1087852b¶m1=value1¶m2=value2"
#EXT-X-VERSION:2
#EXT-X-MEDIA-SEQUENCE:1
#EXTINF:10,
http://myserver/playlist/336385.smil/segment1_3_av.ts?e=6889c9ad1087852b¶m1=value1¶m2=value2
#EXTINF:10,
http://myserver/playlist/336385.smil/segment2_3_av.ts?e=6889c9ad1087852b¶m1=value1¶m2=value2
#EXTINF:10,
http://myserver/playlist/336385.smil/segment3_3_av.ts?e=6889c9ad1087852b¶m1=value1¶m2=value2
#EXTINF:10,
http://myserver/playlist/336385.smil/segment4_3_av.ts?e=6889c9ad1087852b¶m1=value1¶m2=value2
#EXTINF:10,
http://myserver/playlist/336385.smil/segment5_3_av.ts?e=6889c9ad1087852b¶m1=value1¶m2=value2
#EXTINF:10,
http://myserver/playlist/336385.smil/segment6_3_av.ts?e=6889c9ad1087852b¶m1=value1¶m2=value2
#EXT-X-ENDLIST
播放列表工作正常,播放没问题!显然用这些参数手动修改m3u8并不理想,有没有办法为url调用自动设置这些参数?