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);
       }} // ...

 



  • 2020-12-06 16:46:11

    git撤销pull

    刚刚不小心pull了一下,有错误,想撤回怎么办。

  • 2020-12-06 19:05:13

    visual studio 配置 intellij idea快捷键

    我原本从intellij idea转换到visual studio是因为webstorm没办法远程开发,而visual studio有remote wsl,和remote ssh,看着挺不错的样子。

  • 2020-12-06 20:38:30

    intellij idea远程开发remote

    开发时一般的平台都是windows,但windows对开发极其不友好,一般都会在本地开启虚拟机,安装上linux环境进行项目的部署测试。下面介绍一种windows主机与linux虚拟机代码同步的方法。这个工具适用于jerbrains公司旗下的很多产品,比如idea、webstrom、phpstrom等。但是要注意你安装的IDE必须是专业版的,社区版的IDE是没有这个代码同步功能的哦!

  • 2020-12-07 05:46:56

    npm设置和取消代理的方法

    有时候是设置了全局代理对npm并不生效,不如直接给npm设置代理,至少在mac电脑我是有这种感觉的。

  • 2020-12-07 15:04:03

    node开发邮件系统总结

    因为multipart这种形式比较复杂,因此要利用boundary分割符,将邮件体分割成不同段来进行解析,boundary分为父段和子段,父段一般出现0次或1次,出现在末尾,每个子段中也有content-type和boundary,需要在进行解析,如果遇到i,iii里面的情况可直接解析,如果遇到ii中的情况,再按ii中的步骤进行解析

  • 2020-12-07 15:17:45

    email-templates + mjml 发送邮件

    mjml 是一个很不错的响应式邮件html 内容标签库,email-templates 是一个灵活强大的邮件发送框架,两者集成起来我们 可以设计灵活强大的邮件发送系统,以下是一个简单的集成使用,实际使用还有好多地方需要完善

  • 2020-12-07 15:19:00

    响应式邮件的编写插件介绍mjml

    以前做项目碰到发邮件的需求,邮件模板的编辑就是一件头疼的事。因为虽说邮件是支持 HTML 的,但是确是 HTML 子集程度的支持,所以存在必须通过 <table> 排版的恶心之处,还有很多兼容性的坑。本质上是各家邮件商的标准有差异吧。