如何设置上的MediaPlayer代理 [英] How to set proxy on MediaPlayer

查看:1279
本文介绍了如何设置上的MediaPlayer代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的音乐流程序,我怎么能设置在 android.media.MediaPlayer 代理类流通过代理的网络链接文件?我知道NTCreditional,UsernamePasswordCreditional,Proxy-Authorization头和等在的HttpClient 的URLConnection 。但我不能对 android.media.MediaPlayer 设置代理服务器,我该怎么办呢?

In my music stream program, how can I set proxy on android.media.MediaPlayer class for stream a link file through the proxy network ? I know about NTCreditional, UsernamePasswordCreditional, Proxy-Authorization Header and etc in HttpClient, URLConnection. But I can not set proxy on android.media.MediaPlayer, how can I do it?

感谢您提前:)

推荐答案

不幸的是MediaPlayer的API不会在目前提供了一个现成的使用方法的代理服务器设置。

Unfortunately MediaPlayer API doesn't provide a ready-to-use method for proxy setting at the moment.

有一种可能的解决方法,但很肮脏的:

There is a possible workaround but quite dirty:

  1. 从remoteUrl HTTP下载媒体内容://远程主机:80 /音乐,使用任何技术,您熟悉,插座,HttpClient的等,处理代理身份验证正确这里。
  2. 在本地(在移动设备上)打开一个套接字和写入下载数据到这个套接字的OutputStream的,其实我们要的是重新发布该下载内容保存到一个localUrl 的http://本地主机:8081 /音乐我们的移动设备上运行。
  3. 在饲料这localUrl到您的MediaPlayer: mediaPlayer.setDataSource(localURL); 而不是 mediaPlayer.setDataSource(remoteURL);
  1. Download the media contents from the remoteUrl http://remotehost:80/music, using whatever technology you familiar with, socket, httpClient and etc. and handle proxy authentication properly here.
  2. Open a socket locally (on your mobile device) and write the downloaded data to this socket's OutputStream, what we actually want is republish the downloaded contents to a localUrl http://localhost:8081/music running on our mobile device.
  3. Feed this localUrl to your MediaPlayer: mediaPlayer.setDataSource(localURL); instead of mediaPlayer.setDataSource(remoteURL);.
  • 相似,所以讨论:音频流缓冲
  • <一个href="http://$c$c.google.com/p/npr-android-app/source/browse/Npr/src/org/npr/android/news/StreamProxy.java"相对=nofollow> StreamProxy源$ C ​​$从NPR-的Andr​​oid附录C

Related Materials:

  • Similar SO discussion: Audio stream buffering
  • StreamProxy source code from npr-android-app
  • 希望这是有意义的。

    这篇关于如何设置上的MediaPlayer代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆