gpt4 book ai didi

Android HLS 播放 : Passing url parameters as headers in Mediaplayer. setDataSource() 无法正常工作

转载 作者:可可西里 更新时间:2023-11-01 16:34:07 29 4
gpt4 key购买 nike

我在服务器上托管了一个 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&param1=value1&param2=value2

setDataSource (Context context, Uri uri, Map headers) 上将 header 设置为键值对不起作用,至少我正在尝试的方式。以下是我如何从原始 url 参数创建 header :

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'>'),但是添加这些 header 不起作用。

如果我通过播放列表 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&param1=value1&param2=value2"
#EXT-X-VERSION:2
#EXT-X-MEDIA-SEQUENCE:1
#EXTINF:10,
http://myserver/playlist/336385.smil/segment1_3_av.ts?e=6889c9ad1087852b&param1=value1&param2=value2
#EXTINF:10,
http://myserver/playlist/336385.smil/segment2_3_av.ts?e=6889c9ad1087852b&param1=value1&param2=value2
#EXTINF:10,
http://myserver/playlist/336385.smil/segment3_3_av.ts?e=6889c9ad1087852b&param1=value1&param2=value2
#EXTINF:10,
http://myserver/playlist/336385.smil/segment4_3_av.ts?e=6889c9ad1087852b&param1=value1&param2=value2
#EXTINF:10,
http://myserver/playlist/336385.smil/segment5_3_av.ts?e=6889c9ad1087852b&param1=value1&param2=value2
#EXTINF:10,
http://myserver/playlist/336385.smil/segment6_3_av.ts?e=6889c9ad1087852b&param1=value1&param2=value2
#EXT-X-ENDLIST

播放列表工作正常,播放没问题!显然手动修改m3u8这些参数并不理想,有没有办法自动设置url调用的这些参数?

最佳答案

来不及回答了。但可能对你有帮助。我没有测试,但问题出在你的编码方式上。特别是在以下几行中。

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");
}

可能是这样

for(int i= 0;i<paramsSplit.length;i++)
{
String key = paramsSplit[i].substring(0, paramsSplit[i].indexOf("="));
String value = paramsSplit[i].substring(paramsSplit[i].indexOf("=")+1, paramsSplit[i].length() );
headers.put(key, value);//e.g headers.put("param1", "value1");
}

请尝试借助Log进行验证。

关于Android HLS 播放 : Passing url parameters as headers in Mediaplayer. setDataSource() 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17834794/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com