2

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 :)

yorkw
  • 40,926
  • 10
  • 117
  • 130
Hossein Mobasher
  • 4,382
  • 5
  • 46
  • 73

1 Answers1

3

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:

  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);.

Related Materials:

Hope this make sense.

Community
  • 1
  • 1
yorkw
  • 40,926
  • 10
  • 117
  • 130