public Uri download(String apath) {
try {
Log.i("freshhhhhhhhh", apath);
final URL RTUrl;
RTUrl = new URL(apath);
URLConnection urlConnection = RTUrl.openConnection();
String string = urlConnection.getContentType();
// string="audio.amr";
Log.i("Atdownloaderclass", "string" + string);
// Log.i("sizw","string"+size);
String[] str = null;
str = string.split("\\/");
file2 = "3gp";
file1 = "video";
videoFile = new File("/sdcard/video/" + file1 + "." + file2);
// }
Log.i("ValueofaudioFile at rtdc", "::::" + videoFile);
InputStream is = urlConnection.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
new File(videoFile.getParent()).mkdirs();
videoFile.createNewFile();
FileOutputStream fos = new FileOutputStream(videoFile);
int tempByte;
StringBuffer sb = new StringBuffer();
while ((tempByte = bis.read()) != -1) {
sb.append((char) tempByte);
fos.write(tempByte);
buffersize = sb.length();
// Log.i("====================size1", "::::" + buffersize);
reportFoundEntry("" + buffersize);
}
if(size==buffersize)
{
Log.i("tag================","if");
progrsDialog.dismiss();
btn_playVideo.setEnabled(true);
btn_Streamvideo.setEnabled(false);
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
// ErrorURL.errorType = ErrorURL.ContactError;
videoFile.delete();
e.printStackTrace();
}
return RingtoneUri();
}
private Uri RingtoneUri() {
// TODO Auto-generated method stub
if (checkFilevalidity(videoFile, size)) {
path = Uri.fromFile(videoFile);
if (path != null) {
path.toString();
// String
// rttUrl=ErrorURL.errorURL(context,tranid.getTranid());
Log.i("rttUrl**********", path.toString());
Log.i("file1111111111111111", file1);
Log.i("file2222222222222222", file2);
} else {
}
return path;
}
return path;
}
private boolean checkFilevalidity(File audioFile2, Integer valueOf) {
// TODO Auto-generated method stub
if (audioFile2.length() >= valueOf)
return true;
else {
// ErrorURL.errorType = ErrorURL.ContactError;
audioFile2.delete();
return false;
}
}
private void reportFoundEntry(final String name/* , final int i */) {
progressHandler.post(new Runnable() {
public void run() {
// getProgressText().setText(i + " entries found");
getCurrentEntry().setText(name);
}
});
}
try {
Log.i("freshhhhhhhhh", apath);
final URL RTUrl;
RTUrl = new URL(apath);
URLConnection urlConnection = RTUrl.openConnection();
String string = urlConnection.getContentType();
// string="audio.amr";
Log.i("Atdownloaderclass", "string" + string);
// Log.i("sizw","string"+size);
String[] str = null;
str = string.split("\\/");
file2 = "3gp";
file1 = "video";
videoFile = new File("/sdcard/video/" + file1 + "." + file2);
// }
Log.i("ValueofaudioFile at rtdc", "::::" + videoFile);
InputStream is = urlConnection.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
new File(videoFile.getParent()).mkdirs();
videoFile.createNewFile();
FileOutputStream fos = new FileOutputStream(videoFile);
int tempByte;
StringBuffer sb = new StringBuffer();
while ((tempByte = bis.read()) != -1) {
sb.append((char) tempByte);
fos.write(tempByte);
buffersize = sb.length();
// Log.i("====================size1", "::::" + buffersize);
reportFoundEntry("" + buffersize);
}
if(size==buffersize)
{
Log.i("tag================","if");
progrsDialog.dismiss();
btn_playVideo.setEnabled(true);
btn_Streamvideo.setEnabled(false);
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
// ErrorURL.errorType = ErrorURL.ContactError;
videoFile.delete();
e.printStackTrace();
}
return RingtoneUri();
}
private Uri RingtoneUri() {
// TODO Auto-generated method stub
if (checkFilevalidity(videoFile, size)) {
path = Uri.fromFile(videoFile);
if (path != null) {
path.toString();
// String
// rttUrl=ErrorURL.errorURL(context,tranid.getTranid());
Log.i("rttUrl**********", path.toString());
Log.i("file1111111111111111", file1);
Log.i("file2222222222222222", file2);
} else {
}
return path;
}
return path;
}
private boolean checkFilevalidity(File audioFile2, Integer valueOf) {
// TODO Auto-generated method stub
if (audioFile2.length() >= valueOf)
return true;
else {
// ErrorURL.errorType = ErrorURL.ContactError;
audioFile2.delete();
return false;
}
}
private void reportFoundEntry(final String name/* , final int i */) {
progressHandler.post(new Runnable() {
public void run() {
// getProgressText().setText(i + " entries found");
getCurrentEntry().setText(name);
}
});
}
No comments:
Post a Comment