本文来自http://blog.csdn.net/hellogv/ ,引用必须注明出处!
本文是在《Android MediaPlayer与Http Proxy结合之提高篇》基础上,进一步优化代理服务器,支持了Http的302、301重定向,获取Http Request和Http Response的文本内容。本文以视频播放结合Http Proxy,讲述MediaPlayer播放过程中的握手过程。
吐槽一下:用google搜索“代理服务器”无效,所以本文用Media Proxy,大家懂的......
先来看看本文程序运行的截屏动画:
再来看看程序运行时输出的Log信息.....这里是关键:
07-29 15:51:30.692: E/HttpGetProxy(449): ..........sckPlayer connected.......... MediaPlayer发出请求
07-29 15:51:30.692: E/to Media Server---->(449): GET /vids/family_guy_penis_car.3gp HTTP/1.1
07-29 15:51:30.692: E/to Media Server---->(449): User-Agent: stagefright/1.0 (Linux;Android 2.2)
07-29 15:51:30.692: E/to Media Server---->(449): Host: daily3gp.com
07-29 15:51:30.692: E/to Media Server---->(449):
07-29 15:51:31.119: E/HttpGetProxy(449): ..........remote Server connected..........
07-29 15:51:31.122: E/HttpGetProxy(449): ..........remote start to receive..........
07-29 15:51:31.775: E/from Media Server---->(449): HTTP/1.1 200 OK
07-29 15:51:31.775: E/from Media Server---->(449): Date: Sun, 29 Jul 2012 15:51:33 GMT
07-29 15:51:31.775: E/from Media Server---->(449): Server: Apache
07-29 15:51:31.775: E/from Media Server---->(449): Last-Modified: Thu, 14 Jan 2010 23:29:02 GMT
07-29 15:51:31.775: E/from Media Server---->(449): Accept-Ranges: bytes
07-29 15:51:31.775: E/from Media Server---->(449): Content-Length: 754777
07-29 15:51:31.775: E/from Media Server---->(449): Content-Type: video/3gpp
07-29 15:51:34.512: E/HttpGetProxy(449): ..........sckPlayer connected..........MediaPlayer发出请求
07-29 15:51:34.532: E/to Media Server---->(449): GET /vids/family_guy_penis_car.3gp HTTP/1.1
07-29 15:51:34.532: E/to Media Server---->(449): User-Agent: stagefright/1.0 (Linux;Android 2.2)
07-29 15:51:34.532: E/to Media Server---->(449): Host: daily3gp.com
07-29 15:51:34.532: E/to Media Server---->(449): Range: bytes=720896-
07-29 15:51:34.532: E/to Media Server---->(449):
07-29 15:51:34.873: E/HttpGetProxy(449): ..........remote Server connected..........
07-29 15:51:34.873: E/HttpGetProxy(449): ..........remote start to receive..........
07-29 15:51:35.505: E/from Media Server---->(449): HTTP/1.1 206 Partial Content
07-29 15:51:35.505: E/from Media Server---->(449): Date: Sun, 29 Jul 2012 15:51:36 GMT
07-29 15:51:35.505: E/from Media Server---->(449): Server: Apache
07-29 15:51:35.505: E/from Media Server---->(449): Last-Modified: Thu, 14 Jan 2010 23:29:02 GMT
07-29 15:51:35.505: E/from Media Server---->(449): Accept-Ranges: bytes
07-29 15:51:35.505: E/from Media Server---->(449): Content-Length: 33881
07-29 15:51:35.505: E/from Media Server---->(449): Content-Range: bytes 720896-754776/754777
07-29 15:51:35.505: E/from Media Server---->(449): Content-Type: video/3gpp
07-29 15:51:38.754: E/HttpGetProxy(449): ..........over..........
07-29 15:51:51.461: E/HttpGetProxy(449): ..........sckPlayer connected..........MediaPlayer发出请求
07-29 15:51:51.471: E/to Media Server---->(449): GET /vids/family_guy_penis_car.3gp HTTP/1.1
07-29 15:51:51.471: E/to Media Server---->(449): User-Agent: stagefright/1.0 (Linux;Android 2.2)
07-29 15:51:51.471: E/to Media Server---->(449): Host: daily3gp.com
07-29 15:51:51.471: E/to Media Server---->(449): Range: bytes=196608-
07-29 15:51:51.471: E/to Media Server---->(449):
07-29 15:51:51.722: E/HttpGetProxy(449): ..........remote Server connected..........
07-29 15:51:51.722: E/HttpGetProxy(449): ..........remote start to receive..........
07-29 15:51:52.285: E/from Media Server---->(449): HTTP/1.1 206 Partial Content
07-29 15:51:52.285: E/from Media Server---->(449): Date: Sun, 29 Jul 2012 15:51:53 GMT
07-29 15:51:52.285: E/from Media Server---->(449): Server: Apache
07-29 15:51:52.285: E/from Media Server---->(449): Last-Modified: Thu, 14 Jan 2010 23:29:02 GMT
07-29 15:51:52.285: E/from Media Server---->(449): Accept-Ranges: bytes
07-29 15:51:52.285: E/from Media Server---->(449): Content-Length: 558169
07-29 15:51:52.285: E/from Media Server---->(449): Content-Range: bytes 196608-754776/754777
07-29 15:51:52.285: E/from Media Server---->(449): Content-Type: video/3gpp
07-29 15:51:54.812: E/HttpGetProxy(449): ..........sckPlayer connected..........MediaPlayer发出请求
07-29 15:51:54.822: E/to Media Server---->(449): GET /vids/family_guy_penis_car.3gp HTTP/1.1
07-29 15:51:54.822: E/to Media Server---->(449): User-Agent: stagefright/1.0 (Linux;Android 2.2)
07-29 15:51:54.822: E/to Media Server---->(449): Host: daily3gp.com
07-29 15:51:54.822: E/to Media Server---->(449): Range: bytes=589824-
07-29 15:51:54.822: E/to Media Server---->(449):
07-29 15:51:55.117: E/HttpGetProxy(449): ..........remote Server connected..........
07-29 15:51:55.117: E/HttpGetProxy(449): ..........remote start to receive..........
07-29 15:51:55.693: E/from Media Server---->(449): HTTP/1.1 206 Partial Content
07-29 15:51:55.693: E/from Media Server---->(449): Date: Sun, 29 Jul 2012 15:51:57 GMT
07-29 15:51:55.693: E/from Media Server---->(449): Server: Apache
07-29 15:51:55.693: E/from Media Server---->(449): Last-Modified: Thu, 14 Jan 2010 23:29:02 GMT
07-29 15:51:55.693: E/from Media Server---->(449): Accept-Ranges: bytes
07-29 15:51:55.693: E/from Media Server---->(449): Content-Length: 164953
07-29 15:51:55.693: E/from Media Server---->(449): Content-Range: bytes 589824-754776/754777
07-29 15:51:55.693: E/from Media Server---->(449): Content-Type: video/3gpp
07-29 15:51:59.620: E/HttpGetProxy(449): ..........over..........
从截屏动画和Log信息看出,手动seek一次,但MediaPlayer进行了多次Range请求,这说明了“MediaPlayer会自动seek”,或许与MediaPlayer本地缓存有关。另外,不同硬解厂家实现的MediaPlayer估计会有不同的操作。
本文的代码可以到这里下载:
http://download.csdn.net/detail/hellogv/4463651
HttpGetProxy.JAVA还是本文的关键部分: