buttonRecording.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(intent, REQUEST_VIDEO_CAPTURED);
}});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if(resultCode == RESULT_OK){
if(requestCode == REQUEST_VIDEO_CAPTURED){
Uri selectedVideoUri = data.getData();
Log.d("uriiiiiiiiiiiii", "uriiiiiiiiiiiiiiiii"+selectedVideoUri);
filePath = null;
try {
// OI FILE Manager
String filemanagerstring = selectedVideoUri.getPath();
Log.d("uriiiiiiiiiiiii", "uriiiiiiiiiiiiiiiii"+filemanagerstring);
// MEDIA GALLERY
String selectedImagePath = getPath(selectedVideoUri);
Log.d("uriiiiiiiiiiiii", "uriiiiiiiiiiiiiiiii"+selectedImagePath);
if (selectedImagePath != null) {
filePath = selectedImagePath;
Log.d("uriiiiiiiiiiiii", "uriiiiiiiiiiiiiiiii"+selectedImagePath);
} else if (filemanagerstring != null) {
filePath = filemanagerstring;
Log.d("uriiiiiiiiiiiii", "uriiiiiiiiiiiiiiiii"+filePath);
} else {
Toast.makeText(getApplicationContext(),"Unknown path", Toast.LENGTH_LONG).show();
Log.e("Bitmap", "Unknown path");
}
if (filePath != null) {
editpath.setText(filePath.toString());
bmp=ThumbnailUtils.createVideoThumbnail(filePath, Thumbnails.MINI_KIND);
videothum.setImageBitmap(bmp);
} else {
bmp = null;
}
}
catch (Exception e) {
Toast.makeText(getApplicationContext(), "Internal error",
Toast.LENGTH_LONG).show();
Log.e(e.getClass().getName(), e.getMessage(), e);
}
}
else
if(resultCode == RESULT_CANCELED){
uriVideo = null;
Toast.makeText(VideoCapturingusingIntentActivity.this,"Cancelled!",
Toast.LENGTH_LONG)
.show();
}
}
}
public String getPath(Uri uri) {
String[] projection = { MediaStore.Video.Media.DATA};
Cursor cursor = managedQuery(uri, projection, null, null, null);
if (cursor != null) {
// HERE YOU WILL GET A NULLPOINTER IF CURSOR IS NULL
// THIS CAN BE, IF YOU USED OI FILE MANAGER FOR PICKING THE MEDIA
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} else
return null;
}
:-)
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(intent, REQUEST_VIDEO_CAPTURED);
}});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if(resultCode == RESULT_OK){
if(requestCode == REQUEST_VIDEO_CAPTURED){
Uri selectedVideoUri = data.getData();
Log.d("uriiiiiiiiiiiii", "uriiiiiiiiiiiiiiiii"+selectedVideoUri);
filePath = null;
try {
// OI FILE Manager
String filemanagerstring = selectedVideoUri.getPath();
Log.d("uriiiiiiiiiiiii", "uriiiiiiiiiiiiiiiii"+filemanagerstring);
// MEDIA GALLERY
String selectedImagePath = getPath(selectedVideoUri);
Log.d("uriiiiiiiiiiiii", "uriiiiiiiiiiiiiiiii"+selectedImagePath);
if (selectedImagePath != null) {
filePath = selectedImagePath;
Log.d("uriiiiiiiiiiiii", "uriiiiiiiiiiiiiiiii"+selectedImagePath);
} else if (filemanagerstring != null) {
filePath = filemanagerstring;
Log.d("uriiiiiiiiiiiii", "uriiiiiiiiiiiiiiiii"+filePath);
} else {
Toast.makeText(getApplicationContext(),"Unknown path", Toast.LENGTH_LONG).show();
Log.e("Bitmap", "Unknown path");
}
if (filePath != null) {
editpath.setText(filePath.toString());
bmp=ThumbnailUtils.createVideoThumbnail(filePath, Thumbnails.MINI_KIND);
videothum.setImageBitmap(bmp);
} else {
bmp = null;
}
}
catch (Exception e) {
Toast.makeText(getApplicationContext(), "Internal error",
Toast.LENGTH_LONG).show();
Log.e(e.getClass().getName(), e.getMessage(), e);
}
}
else
if(resultCode == RESULT_CANCELED){
uriVideo = null;
Toast.makeText(VideoCapturingusingIntentActivity.this,"Cancelled!",
Toast.LENGTH_LONG)
.show();
}
}
}
public String getPath(Uri uri) {
String[] projection = { MediaStore.Video.Media.DATA};
Cursor cursor = managedQuery(uri, projection, null, null, null);
if (cursor != null) {
// HERE YOU WILL GET A NULLPOINTER IF CURSOR IS NULL
// THIS CAN BE, IF YOU USED OI FILE MANAGER FOR PICKING THE MEDIA
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} else
return null;
}
:-)
No comments:
Post a Comment