问题描述
在我的音乐流程序,我怎么能设置在 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:
- 从remoteUrl
HTTP下载媒体内容://远程主机:80 /音乐
,使用任何技术,您熟悉,插座,HttpClient的等,处理代理身份验证正确这里。 - 在本地(在移动设备上)打开一个套接字和写入下载数据到这个套接字的OutputStream的,其实我们要的是重新发布该下载内容保存到一个localUrl
的http://本地主机:8081 /音乐
我们的移动设备上运行。 - 在饲料这localUrl到您的MediaPlayer:
mediaPlayer.setDataSource(localURL);
而不是mediaPlayer.setDataSource(remoteURL);
。
- 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. - 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. - Feed this localUrl to your MediaPlayer:
mediaPlayer.setDataSource(localURL);
instead ofmediaPlayer.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-的Android附录C
Related Materials:
- Similar SO discussion: Audio stream buffering
- StreamProxy source code from npr-android-app
希望这是有意义的。
这篇关于如何设置上的MediaPlayer代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!