2

我正在使用具有代理身份验证的网络,需要用户名/密码进行身份验证。我想流式传输音乐,我知道MediaPlayer只能从直接网络流式传输。现在,我想使用HttpClient或其他网络类来下载媒体并在下载时在本地播放,我知道HttpClient通过代理网络使用下载:

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
}

如何将缓冲区字节链接到MediaPlayer对象并成功播放媒体?请给我一个最佳性能解决方案。

感谢您的提前:)

4

0 回答 0