美文网首页音视频开发集锦
ijkplayer设置http_proxy/cookie

ijkplayer设置http_proxy/cookie

作者: 碉胖纸 | 来源:发表于2017-05-22 15:55 被阅读1464次

    参考:
    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

    相关文章

      网友评论

        本文标题:ijkplayer设置http_proxy/cookie

        本文链接:https://www.haomeiwen.com/subject/lezbxxtx.html