Create a proxy server in android to intercept media player request and response

2020-12-16 22:06:12

参考地址 Create a proxy server in android to intercept media player request and response


1

I am trying to extract ID3 tags from live streams on an android device. Extraction of ID3 tags from live streams in not available in android by default.

The approach I want to follow is to intercept the media player request and response in a proxy server and analyze the byte data to extract ID3 tags. access to media player cache gives us a rough idea to achieve this, but I am not sure if we will be able to proxy the media player request/response. If anyone has done this or has any pointers on it, it would be very helpful ...

Thanks

   

 

创建 30 12月. 13 

2

You have to provide the MediaPlayer a localhost address and listen on the port you specify. For instance, if you have set up your proxy server to listen on port 8090, you might set the data source like:

mp.setDataSource(whateverContext, Uri.parse("http://127.0.0.1:8090"));

You will then receive requests from the MediaPlayer to which you have to respond. In order to respond properly, you simply forward the request to the remote media server (the original URI). To keep it simple you can use AndroidHttpClient to make the requests. When you get responses from the remote server, you need to write that data to the socket opened by the MediaPlayer, first the HTTP headers, followed by the entity's binary data when that is relevant.

Edit:

I haven't looked at this project very much, but it is oft mentioned as the archetypal project for using a proxy with the MediaPlayer. Their class that does the proxy work looks to be StreamProxy.java. They've used DefaultHttpClient instead of AndroidHttpClient, but it's basically the same as I described. Notice in particular their processRequest method. The following contains excerpts from that method with my comments:

// Execute the HttpRequest and receive an HttpResponseHttpResponse realResponse = download(url);// ...// Retrieve the response entity as an InputStreamInputStream data = realResponse.getEntity().getContent();// ...try {
       // The response headers have been concatenated into httpString,
       // so write the headers to the client socket
       byte[] buffer = httpString.toString().getBytes();
       client.getOutputStream().write(buffer, 0, buffer.length);
       // Write the entity data to the client socket (repeatedly read from
       // the entity stream and write to the client socket)
       byte[] buff = new byte[1024 * 50];
       while (isRunning && (readBytes = data.read(buff, 0, buff.length)) != -1) {
           client.getOutputStream().write(buff, 0, readBytes);
       }} // ...

 



  • 2019-03-13 09:38:11

    写入MySQL报错超出 max_allowed_packet 的问题

    MySQL会根据配置文件会限制server接受的数据包的大小。如果写入大数据时,因为默认的配置太小,插入和更新操作会因为 max_allowed_packet 参数限制,而导致失败。

  • 2019-03-15 15:28:33

    10分钟教你搭建自己的ngrok服务器

    内网穿透想必开发过微信的同志都很了解,大部分人选择网上寻找各种现成的,比如ngrok官网、ittun-ngrok、sunny-ngrok或者花生壳之类的。但是世界上没有免费的午餐,要不就是收费,要不就是免费但是偶尔会出现连接失败的问题(当然大多数时间是没有问题的)。

  • 2019-03-15 15:29:53

    丢弃花生壳,搭建自己的ngrok作为内网穿透服务器

    公司没有公网,公司在二级路由下面(就是服务商没有给独立IP,也无法动态获取公网IP),然而公司在开发程序的时候,如对接微信等需要返回数据,或者需要别人能访问我们网址,一般我们就只能购买花生壳内网穿透,但是在使用中发现速度慢,经常掉。所以搭建自己的ngrok服务器来保证内网穿透。

  • 2019-03-15 15:31:21

    内网穿透 ngrok 服务器和客户端配置

    ngrok 简介及作用 ngrok 是一款用 go 语言开发的开源软件,它是一个反向代理,通过在公共的端点和本地运行的 Web 服务器之间建立一个安全的通道。下图简述了 ngrok 的原理。

  • 2019-03-15 15:32:09

    内网打洞以及代码实现

    假设内网的多个ip或者同一ip的不同port,都要访问同一个(外网ip:port)。对NAT来说,从外网接收的包它的(srcIp:srcPort)==(serverIp,serverPort),它的dstIp==natIp,所以NAT只能用dstPort来决定把这个包转发给哪一个(内网Ip:port)

  • 2019-03-15 15:33:08

    Xshell不能按退格、删除键的解决方案

    在使用xshell时,由于每个服务器不同,一些无法使用Backspace键向后删除字符。针对这个问题,本文为大家解答下退格键无法识别如何设置?

  • 2019-03-15 15:49:28

    win10远程桌面连接不上解决方法

    有朋友就感叹电脑的世界真的是很神奇,可以将整个世界连接在一起。如果别人想要摆弄你的电脑,即使不在一个地方也可以利用远程桌面来控制。而这就是所谓的远程控制操作了,大部分人都知道它的作用,不过这也不排除会遇到一些突发情况的时候,例如win10远程桌面连接不上,这该怎么去解决呢?为此,小编给大家带来了解决的图文操作。