2

I am using a network with proxy authentication that require username/password for authentication. I want to stream a music, and i know that MediaPlayer only can stream from a direct network. Now, i want to use HttpClient or other network classes to download the media and play it locally in download time, I know about downloading with using HttpClient through the proxy network :

String M_url = "http://printf.ir/music/01.wma";

DefaultHttpClient request = new DefaultHttpClient();
request.getCredentialsProvider().setCredentials(
    AuthScope.ANY,
    new NTCredentials(proxyUser, proxyPassword,
              proxyAddress, proxyDomain));
HttpHost p = new HttpHost(proxyAddress, proxyPort);
request.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,p);

URL url = new URL(M_url);
HttpGet httpGet = new HttpGet(new URI(url.getProtocol(), url.getHost(),
              url.getPath(), url.getQuery(), null));

byte[] buffer = new byte[5 * 1024];
int readBytes = 0;

InputStream in = request.execute(httpGet).getEntity().getContent();

while ( (readBytes = in.read(buffer, 0, 1024)) != -1){
     //buffer is completed
}

How can i link buffer bytes to MediaPlayer object and play media successfully? Please give me a best performance solution.

Thanks for your advance :)

Hossein Mobasher
  • 4,382
  • 5
  • 46
  • 73
  • 1
    Have you tried StreamProxy approach yet? The [source](http://code.google.com/p/npr-android-app/source/browse/Npr/src/org/npr/android/news/StreamProxy.java) contains pretty much ready-baked code you need. – yorkw May 17 '12 at 10:44
  • 1
    Yes, but i do not know how to use it! – Hossein Mobasher May 17 '12 at 10:49
  • 1
    Check out sample usage in Eugenious's answer [here](http://stackoverflow.com/questions/4557450/audio-stream-buffering/4563794#4563794). – yorkw May 17 '12 at 11:01
  • What does StreamProxy do ? can you explain ? – Hossein Mobasher May 17 '12 at 11:57
  • Download media contents from remote server and re-publish it to a local url:port that can be feed into MediaPlayer, all happened in background thread. – yorkw May 17 '12 at 22:46

0 Answers0