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-11-17 17:08:28

    用js编写WebAssembly ,WebAssembly 现状与实战

    自从 JavaScript 诞生起到现在已经变成最流行的编程语言,这背后正是 Web 的发展所推动的。Web 应用变得更多更复杂,但这也渐渐暴露出了 JavaScript 的问题:

  • 2020-11-17 17:28:06

    AssemblyScript 开发WebAssembly 教程

    WebAssembly 以及通过 AssemblyScript 的扩展,不会使每个网站都神奇地变得更快,但是这并不重要。 WebAssembly 之所以令人兴奋,是因为它可以使更多的应用在 Web 变得中可行。

  • 2020-11-17 21:15:48

    如何保障 API 接口的安全性?前端如何加密

    一、1. HTTP 请求中的来源识别 二、2. 数据加密 三、3. 数据签名 四、4. 时间戳 五、5. AppID 六、6. 参数整体加密 七、7. 限流 八、8. 黑名单 九、1. 压缩 十、2. 混淆 undefined、3. 加密

  • 2020-11-18 14:34:00

    当你写爬虫抓不到APP请求包的时候该怎么办?

    提示:因为高级篇以后的APP将无法使用很通用的方式处理,每种类型甚至是每个APP的反抓包处理方式都会有差别,所以这个系列以后会以【高级篇-具体类型】的形式来写。

  • 2020-11-21 20:41:51

    Kotlin Sealed class类详解

    Sealed class(密封类) 是一个有特定数量子类的类,看上去和枚举有点类似,所不同的是,在枚举中,我们每个类型只有一个对象(实例);而在密封类中,同一个类可以拥有几个对象。

  • 2020-11-22 20:53:43

    Dagger2之Kotlin写法

    修饰构造方法 修饰变量,在宿主类里,引入要注入的实例

  • 2020-11-22 20:56:13

    Dagger2使用详解

    简单的说,就是一个工厂模式,由Dagger负责创建工厂,帮忙生产instance。遵从Java规范JSR 330,可以使用这些注解。现在不研究Dagger2是如何根据注解去生成工厂的,先来看看工厂是什么东西,理解为什么可以实现了DI(Dependency Injection),如何创建IoC(Inverse of Control)容器。

  • 2020-11-22 21:00:28

    dagger.android--Fragment,BaseFragment

    1 使用Fragment参数来代替Activity参数 2 使用 @FragmentKey来代替@ActivityKey 3 使用HasFragmentInjector来代替@HasActivityInjector 4 AndroidInjection.inject(Fragment)方法,在Fragment的onAttach()中调用,而不是在onCreate()中 5 Fragment的Module添加位置,和Activity是不同的,它取决于Fragment需要的其他依赖注入

  • 2020-11-22 21:12:30

    Dependency Injection with Dagger2,Fragment

    標註@Provides的method若有parameter的話,Dagger會找出其擁有的該型態物件來使用。我們在Module內新增了DataModel將其列入Dagger的管理下,接著在provideFactory()增加parameter變成provideFactory(DataModel dataModel),Dagger就會找出其管理的DataModel給provideFactory使用。