I\'m developing an app which needs to get music file by streaming for playing live.
In the request song api I can specify the bandwith (eg: 50kbps, 100kbps, 300, 600 or
protected String doInBackground(String... urls) {
String response = "";
startTime = System.currentTimeMillis();
for (String url : urls) {
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
try {
HttpResponse execute = client.execute(httpGet);
InputStream content = execute.getEntity().getContent();
BufferedReader buffer = new BufferedReader(
new InputStreamReader(content));
String s = "";
while ((s = buffer.readLine()) != null) {
response += s;
}
endTime = System.currentTimeMillis();
} catch (Exception e) {
e.printStackTrace();
}
}
return response;
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
long dataSize = result.length() / 1024;
takenTime = endTime - startTime;
long s = takenTime / 1000;
double speed = dataSize / s;
Toast.makeText(context, "" + s + "kbps", Toast.LENGTH_SHORT).show();
}