In my app, I want to use Camera option, so i am using below code to capture the videos.
public class CameraDemoActivity extends Activity
{
private static final int CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE = 200;
private Uri fileUri;
public static final int MEDIA_TYPE_VIDEO = 2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Context context = this;
PackageManager packageManager = context.getPackageManager();
// if device support camera?
if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
//yes
Log.i("camera", "This device has camera!");
Toast.makeText(getBaseContext(), "Camera device", Toast.LENGTH_LONG).show();
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO); // create a file to save the video
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT,2);
intent.putExtra(MediaStore.INTENT_ACTION_VIDEO_CAMERA, true);
intent.putExtra(MediaStore.MEDIA_SCANNER_VOLUME, 100);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); // set the video image quality to high
// start the Video Capture Intent
startActivityForResult(intent, CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE);
}else{
//no
Log.i("camera", "This device has no camera!");
Toast.makeText(getBaseContext(), "No Camera device", Toast.LENGTH_LONG).show();
}
}
private static Uri getOutputMediaFileUri(int type){
return Uri.fromFile(getOutputMediaFile(type));
}
/** Create a File for saving an image or video */
private static File getOutputMediaFile(int type)
{
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS), "MyCameraApp");
if (! mediaStorageDir.exists()){
if (! mediaStorageDir.mkdirs()){
System.out.println("MyCameraApp");
return null;
}
}
// Create a media file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File mediaFile;
if(type == MEDIA_TYPE_VIDEO)
{
mediaFile = new File(mediaStorageDir.getPath() + File.separator +
"VID_"+ timeStamp + ".mp4");
}
else
{
return null;
}
return mediaFile;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
// Video captured and saved to fileUri specified in the Intent
Toast.makeText(this, "Video saved to:\n" +
data.getData(), Toast.LENGTH_LONG).show();
System.out.println("Video saved to:"+data.getData());
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, "video cancel", Toast.LENGTH_LONG).show();
// User cancelled the video capture
} else {
System.out.println("video capyured failed.>.1!!!!");
// Video capture failed, advise user
}
}
}
}
In above code, i am getting video screen in emulator, but its like recording as squares of boxes, which is black and white boxes...!!!!!!!!!!!
In emulator, i can't get the live videos, it also not enabling web cam also.
Interesting is, this code has successfully run in another computer,(dell webcam). In that machine its enabling web cam and recording videos very slowly, but this is recognsing and enabling camera in emulator.
Another machine is Compaq, unfortunately it has not working and not recognising web cam.
PLEASE ANY Help to activate this webcam facilities.