我正在使用具有代理身份验证的网络,需要用户名/密码进行身份验证。我想流式播放音乐,我知道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
对象并成功播放媒体?请给我一个最佳性能解决方案。
感谢您的进步:)