參考:
1.IJKPlayer問題集錦之不定時更新http://www.reibang.com/p/220b00d00deb#
2.https://github.com/Bilibili/ijkplayer/issues/1150
Map<String, String> headers = new HashMap<>();
Uri uri = Uri.parse(url);
headers.put("Host",uri.getHost());
headers.put("Cookie"," " + cookie + ";\r\n");
headers.put("http_proxy", "http://123.123.123.123:80");
ijkMediaPlayer.setDataSource(uri, headers);
headers也是在內(nèi)部被轉(zhuǎn)化為何issuses一樣的setOption方法
ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT,"http_proxy", "http://123.123.123.123:80");
ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT,"headers", "test");
源碼如下 IjkMediaPlayer.java
/**
* Sets the data source (file-path or http/rtsp URL) to use.
*
* @param path the path of the file, or the http/rtsp URL of the stream you want to play
* @param headers the headers associated with the http request for the stream you want to play
* @throws IllegalStateException if it is called in an invalid state
*/
public void setDataSource(String path, Map<String, String> headers)
throws IOException, IllegalArgumentException, SecurityException, IllegalStateException
{
if (headers != null && !headers.isEmpty()) {
StringBuilder sb = new StringBuilder();
for(Map.Entry<String, String> entry: headers.entrySet()) {
sb.append(entry.getKey());
sb.append(":");
String value = entry.getValue();
if (!TextUtils.isEmpty(value))
sb.append(entry.getValue());
sb.append("\r\n");
setOption(OPT_CATEGORY_FORMAT, "headers", sb.toString());
setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "protocol_whitelist", "async,cache,crypto,file,http,https,ijkhttphook,ijkinject,ijklivehook,ijklongurl,ijksegment,ijktcphook,pipe,rtp,tcp,tls,udp,ijkurlhook,data");
}
}
setDataSource(path);
}
其他可配置的參數(shù)可參考FFmpeg文檔:https://ffmpeg.org/ffmpeg-protocols.html#http