1

我编辑了VideoViewDemo.java(官网提供的 Android Vitamio 演示),目的是在 Vitamio 生成的请求头中添加 cookie 。
(使用方法“setVideoPath”时自动发送标头。)

原始 VideoViewDemo.java:

...
} else {
        /*
         * Alternatively,for streaming media you can use
         * mVideoView.setVideoURI(Uri.parse(URLstring));
         */
        mVideoView.setVideoPath(path);
        mVideoView.setMediaController(new MediaController(this));
        mVideoView.requestFocus();
...


编辑 VideoViewDemo.java:

...
} else {

        Map<String, String> headers = new HashMap<String, String>();
        headers.put("Cookie", "test=abc; test2=def");
        mVideoView.setVideoHeaders(headers);

        /*
         * Alternatively,for streaming media you can use
         * mVideoView.setVideoURI(Uri.parse(URLstring));
         */
        mVideoView.setVideoPath(path);
        mVideoView.setMediaController(new MediaController(this));
        mVideoView.requestFocus();
...


然后我使用Wireshark检查数据包。

我“预期”的结果:

预期结果

我得到的结果:

实际结果

它表明我尝试添加的 cookie 不包含在 Vitamio 生成的请求标头中。
我的代码有什么问题吗?或者有没有其他方法可以实现我的目标?


设备:HTC J Z321e
Android 版本:4.1.1
Vitamio 版本:4.2.0 (2013-12-31)
IDE:Eclipse on Windows 7 32 Bit
图片网址:http: //imgur.com/dY7qajG&lHoxxwo#0

4

2 回答 2

1

终于找到了解决办法。标题是 AVOption 样式,所以应该按以下方式使用:

Map<String, String> headers = new HashMap<String, String>();
headers.put("headers", "Cookie:"+stringCookie+"\r\n"+"User-agent:Mozilla\r\n");
videoView.setVideoURI(Uri.parse(url), headers);
于 2015-06-08T11:08:03.357 回答
1
Map<String, String> headers = new HashMap<String, String>();
headers.put("Cookie", "a=" + cokkievalue);
mVideoView.setVideoURI(Uri.parse(url), headers);

这很完美

于 2015-07-10T07:44:08.103 回答