ijkplayer设置http_proxy/cookie

参考:
1.IJKPlayer问题集锦之不定时更新http://www.jianshu.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也是在内部被转化为何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);
}

其他可配置的参数可参考FFmpeg文档:https://ffmpeg.org/ffmpeg-protocols.html#http

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • afinalAfinal是一个android的ioc,orm框架 https://github.com/yangf...
    passiontim阅读 15,556评论 2 45
  • 大家吼,不知名程序猿小郭同学又冒泡啦,今天是主角是:业界知名,天朝最大异(tong)性交友平台,BILIBILI开...
    恋猫月亮阅读 56,045评论 123 147
  • 不知道从哪一刻开始,朋友、同事、小伙伴坐在一起畅聊的时候,总是少不了谈起微信朋友圈。 “哎,我朋友圈有个小学同学,...
    爱说谎的路人甲阅读 1,717评论 0 3
  • 25年前的今日,母亲生下了我,才有了我的故事。 刚才给母亲打电话后,兔子说了句稍显深沉的话,“我只是觉得生日为什么...
    写作者陈菁阅读 463评论 0 0
  • 赋歌 太阳出来我爬山坡爬到山顶我想唱歌 唱起歌儿来想起了父亲想起父亲来孩子唱起了歌 深沉呼唤着深沉父爱呼唤着归儿归...
    南溪向南北歌流海阅读 221评论 0 0