Tuesday, April 16, 2013

[android help] How to provide progressive audio streaming with progressiv download in Box Api


What i want to do in my project is to play audio songs which are inside my Box account for that i am using box api . As i know we can not provide direct audio streaming for audio files in Box api for that i am trying to implement progressive download and playing audio file from sd card . i know i can play song inside on complete method of download but this is taking more time to download and than playing file . for that what i did i wrote my code for playing audio inside on progress method of downloading file but this method is getting called so many times because of that same song is playing multiple time at a time.


So is there any way to write code for progressive audio playing in Box api .if yes where should i write that ?



* Download a file and put it into the SD card. In your app, you can put the file wherever you have access to.
*/
final Box box = Box.getInstance(Constants.API_KEY);
String PATH = Environment.getExternalStorageDirectory() + "/chaseyourmusic"+folderpath;
File file = new File(PATH);
file.mkdirs();
final java.io.File destinationFile = new java.io.File(PATH + "/"
+ URLEncoder.encode(items[position].name));
/* final java.io.File destinationFile = new java.io.File(Environment.getExternalStorageDirectory() + "/"
+ URLEncoder.encode(items[position].name));*/

final ProgressDialog downloadDialog = new ProgressDialog(Browse.this);
downloadDialog.setMessage("Downloading " + items[position].name);
downloadDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
downloadDialog.setMax((int) items[position].file.getSize());
downloadDialog.setCancelable(true);
downloadDialog.show();

Toast.makeText(getApplicationContext(), "Click BACK to cancel the download.", Toast.LENGTH_SHORT).show();

final Cancelable cancelable = box.download(authToken, items[position].id, destinationFile, null, new FileDownloadListener() {

@Override
public void onComplete(final String status) {
downloadDialog.dismiss();
if (status.equals(FileDownloadListener.STATUS_DOWNLOAD_OK)) {
//Able to play audio here from sd card but this is playing after completion of download only which is taking more time .


}
else if (status.equals(FileDownloadListener.STATUS_DOWNLOAD_CANCELLED)) {
Toast.makeText(getApplicationContext(), "Download canceled.", Toast.LENGTH_LONG).show();
}
}

@Override
public void onIOException(final IOException e) {
e.printStackTrace();
downloadDialog.dismiss();
Toast.makeText(getApplicationContext(), "Download failed " + e.getMessage(), Toast.LENGTH_LONG).show();
}

@Override
public void onProgress(final long bytesDownloaded) {
downloadDialog.setProgress((int) bytesDownloaded);
//Want to write code here but this method is getting called multiple times which is creating problem in playing audio files from sd card .


}
});
downloadDialog.setOnCancelListener(new OnCancelListener() {

@Override
public void onCancel(DialogInterface dialog) {
cancelable.cancel();
}
});


Thanks



.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...