Wednesday, July 27, 2011
Video Streaming On Android
Monday, July 18, 2011
AsynTask, VideoDownload and ProgressBar in Android
public class DownloaderClass extends AsyncTaskIn your activity call this Downloader class by calling execute() method and pass the videoUrl(from the video is be downloaded) and videoPath(where it is to be stored on SDCard){
private boolean stop = false;
private FileOutputStream fileOutputStream;
private InputStream inputStream;
// this is the total size of the file
private int totalSize = 0;
// variable to store total downloaded bytes
private int downloadedSize = 0;
private HttpURLConnection urlConnection;
private File videoFile;
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
showDialog(0);
}
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
// method
// String
// path=Environment.getExternalStorageDirectory().getAbsolutePath()+PATH+fileName;
try {
// set the download URL, a url that points to a file on the
// internet
// this is the file to be downloaded
System.out.println("doInBackground");
URL url = new URL(params[0]);
// create the new connection
urlConnection = (HttpURLConnection) url.openConnection();
// set up some things on the connection
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
// and connect!
urlConnection.connect();
// set the path where we want to save the file
// in this case, going to save it on the root directory of the
// sd card.
// File SDCardRoot = Environment.getExternalStorageDirectory();
String videoPath = SDCARD_ROOT + params[1];
// create a new file, specifying the path, and the filename
// which we want to save the file as.
boolean exists = (new File(videoPath)).exists();
if (!exists) {
new File(videoPath).mkdirs();
}
videoFile = new File(videoPath, VIDEO_NAME);
// this will be used to write the downloaded data into the file
// we
// created
fileOutputStream = new FileOutputStream(videoFile);
// this will be used in reading the data from the internet
inputStream = urlConnection.getInputStream();
// this is the total size of the file
totalSize = urlConnection.getContentLength();
// create a buffer...
byte[] buffer = new byte[1024];
int bufferLength = 0; // used to store a temporary size of the
// buffer
// now, read through the input buffer and write the contents to
// the
// file
while ((bufferLength = inputStream.read(buffer)) > 0 && !stop) {
// add the data in the buffer to the file in the file output
// stream (the file on the sd card
fileOutputStream.write(buffer, 0, bufferLength);
// add up the size so we know how much is downloaded
downloadedSize += bufferLength;
publishProgress((downloadedSize * 100) / totalSize);
// this is where you would do something to report the
// prgress,
// like this maybe
// System.out.println(downloadedSize + "/" + totalSize);
}
// close the output stream when done
fileOutputStream.close();
System.out.println("Downloading finished");
playVideo();
// catch some possible errors...
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onProgressUpdate(Integer... values) {
// TODO Auto-generated method stub
Log.d("% Downloaded : ", "" + values[0]);
progressDialog.setProgress(values[0]);
}
@Override
protected void onCancelled() {
// TODO Auto-generated method stub
// finish();
System.out.println("onCancelled()");
stop = true;
urlConnection.disconnect();
if (fileOutputStream != null) {
try {
fileOutputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
videoFile.delete();
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
super.onPostExecute(result);}}
downloaderClassObj.execute(VIDEO_URL, VIDEO_PATH);
@OverrideFrom your onPreExecute() method in Downloader class call showDialog() to initiate the progressbar.........the onPreExecute() method gets automatically called as soon as execute() method is called..............
protected Dialog onCreateDialog(int id) {
// TODO Auto-generated method stub
progressDialog = new ProgressDialog(this);
progressDialog.setCancelable(true);
progressDialog.setMessage("Downloading...");
// set the progress to be horizontal
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
// reset the bar to the default value of 0
progressDialog.setProgress(0);
progressDialog.setMax(100);
progressDialog.show();
progressDialog.setOnCancelListener(new OnCancelListener() {
public void onCancel(DialogInterface dialog) {
// TODO Auto-generated method stub
downloaderClassObj.cancel(true);
}
});
return progressDialog;
}
Tuesday, July 12, 2011
What a pitiful situation.......
Wednesday, June 15, 2011
Synchronous & Asynchronous Methods
It is so important to know whether a method call is synchronous or asynchronous.
Firstly i'll explain the difference between the two;
Synchronous methods, complete its execution and then returns the control back to where it was called from and the process further continues.
Whereas asynchronous methods when called they get started in their own separate thread, and run independently without affecting the main process thread.
Most of the methods are synchronous as they are easy to handle and operate with, but a few methods like webcomponents are asynchronous. For eg. downloading something while application is running is asynchronous method, also logically it should be so, since the data to be downloaded can be large or depending on network may take longer time, hence the main thread cannot stop for so long.
Monday, May 23, 2011
FrameWork Importance
Wednesday, April 13, 2011
Desktop R&R
Friday, April 8, 2011
BlackBerry Workshop
Mr Pradeep Rao from Research in Motion.
Second spokesperson was Mr Alan Wong who had specially come down from HongKong
to give a handsOn experience of the BB Playbook.
The BB Playbook tablet is a powerful machine with its OS built over the QNX technology,
the OS promises powerful multitasking capabilities and is powered by 1Ghz dual core
processer(make not disclosed) with 1Gb ram.
It has got Flash 10.1 support and a HD display with HDMI port. Rear camera is 5mp while
3mp at the front, and records video at 720p which is lower than that of
Galaxy tab 2(1080p HD recording).
To develop apps on the Playbook and other BB devices there are several options as follows:-
1) Adobe AIR
2) BB Webworks
3) Native SDK
4) Browser development -> HTML5, Flash 10.1 and CSS3.
1) Adobe AIR
-> Uses Flex(SDK) based on the Adobe Flash platform.
-> MXML is used for designing the UI/Front end.
-> Interactivity is achieved through the use of ActionScript.
-> FlashBuilder is the IDE required for developing using Flex and also BB Tablet OS SDK is required to build apps for BB.
-> Apps developed using Flex can be ported to BB, android and iPhone devices.
2) BB webworks
-> It is supported on BB v5.0 onwards.
-> Involves development using HTML5, CSS and JavaScript.
-> Simply we need to design UI in HTML5 and use javascript for interactivities, ZIP all the files and with the issue of a command(bbwp
More information can be found on the following website http://us.blackberry.com/developers/tablet