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?
Thanks for your advance :)
Unfortunately MediaPlayer API doesn't provide a ready-to-use method for proxy setting at the moment.
how can I do it?
There is a possible workaround but quite dirty:
- 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 of mediaPlayer.setDataSource(remoteURL);
.
Related Materials:
- Similar SO discussion: Audio stream buffering
- StreamProxy source code from npr-android-app
Hope this make sense.