ijkplayer設置http_proxy/cookie

參考:
1.IJKPlayer問題集錦之不定時更新http://www.lxweimin.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,047評論 123 147
  • 不知道從哪一刻開始,朋友、同事、小伙伴坐在一起暢聊的時候,總是少不了談起微信朋友圈。 “哎,我朋友圈有個小學同學,...
    愛說謊的路人甲閱讀 1,717評論 0 3
  • 25年前的今日,母親生下了我,才有了我的故事。 剛才給母親打電話后,兔子說了句稍顯深沉的話,“我只是覺得生日為什么...
    寫作者陳菁閱讀 463評論 0 0
  • 賦歌 太陽出來我爬山坡爬到山頂我想唱歌 唱起歌兒來想起了父親想起父親來孩子唱起了歌 深沉呼喚著深沉父愛呼喚著歸兒歸...
    南溪向南北歌流海閱讀 221評論 0 0