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-12-10 21:14:11

    axios文件上传功能+formData

    在项目中使用axios上传文件,记得new一个纯净的axios或者考虑用ajax请求。因为axios在项目估计已经用了全局配置请求头等信息,这里的配置可能被全局请求头拦截,导致请求失败。 2.1构造formData 作者:exmexm 链接:https://www.jianshu.com/p/9c708a47d8a5 来源:简书 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

  • 2019-12-11 16:04:15

    CSS中的 “var()” 和 “:root”

    var() var()函数可以代替元素中任何属性中的值的任何部分。var()函数不能作为属性名、选择器或者其他除了属性值之外的值。(这样做通常会产生无效的语法或者一个没有关联到变量的值。)

  • 2019-12-11 16:18:51

    npm发布vue组件

    开发之前先看看官网的 开发规范 我们开发的之后期望的结果是支持 import、require 或者直接使用 script 标签的形式引入,就像这样

  • 2019-12-11 16:21:00

    .vue文件 加scoped 样式不起作用

    在vue组件中,为了使样式私有化(模块化),不对全局造成污染,在style标签上添加scoped属性,以表示它只属于当下的模块。但是要慎用,因为在我们需要修改公共组件(第三方库或者项目中定制的组件)的样式的时候,scoped会造成很多困难,组要增加额外的复杂度。

  • 2019-12-11 16:22:04

    Vue中的scoped和scoped穿透,scoped原理

    在Vue文件中的style标签上有一个特殊的属性,scoped。当一个style标签拥有scoped属性时候,它的css样式只能用于当前的Vue组件,可以使组件的样式不相互污染。如果一个项目的所有style标签都加上了scoped属性,相当于实现了样式的模块化。

  • 2019-12-12 14:19:32

    laravel自定义分页LengthAwarePaginator

    有时候我们使用larave提供的后台分页数据库查询,有时候限制太多,我们需要自己定制分页功能。 下面是我给大家一个例子,我们可以根据例子,制作自己的分页功能。