1

I use the following code to call existed camera :

// New intent to Camera feature
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
Uri fileUri = Uri.fromFile((new File((new Date()).toString())));  // create a file to save the video

intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);  // set the image file name
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);

I can capture photo, but can not record the video, I received the error Warning : Camera failed

I try to do something related to some solutions but can not receive good result. (Although reset the phone)

Please tell me how to fix this,

Thanks,

P/s : Device - Samsung Galaxy Tab 7 2.2.1

EDIT : I use the following code to receive the response, and response the result resultCode == RESULT_CANCELED

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_SHORT).show();
} else if (resultCode == RESULT_CANCELED) {
    // User cancelled the video capture
    Toast.makeText(this, "User cancelled the video capture", Toast.LENGTH_SHORT).show();
} else {
    // Video capture failed, advise user
    Toast.makeText(this, "Warning : Camera failed", Toast.LENGTH_SHORT).show();
}
Huy Tower
  • 7,769
  • 16
  • 61
  • 86
  • Why don't you check if intent actually returned? similar to this http://developer.android.com/training/camera/videobasics.html also check this thread http://stackoverflow.com/questions/2550743/android-video-capture-sample-app – Boris Ivanov Dec 23 '13 at 11:15
  • @Boris : I edited the code follow your comment. I run the second link (project) also, and i get black screen @@ nothing happen more. – Huy Tower Dec 24 '13 at 02:07
  • you have to create new Activity for adding Surfaceholder and MediaRecorder -class handle videorecording easily – Sanket990 Dec 24 '13 at 04:23
  • Can you publish sample project of your code so it will be easier to try it? – Boris Ivanov Dec 24 '13 at 09:59

1 Answers1

0

I compared your code with Android Guide. The only difference is the file uri. You can try the Google's sample code to get the file uri:

public static final int MEDIA_TYPE_IMAGE = 1;
public static final int MEDIA_TYPE_VIDEO = 2;

/** Create a file Uri for saving an image or video */
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){
    // To be safe, you should check that the SDCard is mounted
    // using Environment.getExternalStorageState() before doing this.

    File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
              Environment.DIRECTORY_PICTURES), "MyCameraApp");
    // This location works best if you want the created images to be shared
    // between applications and persist after your app has been uninstalled.

    // Create the storage directory if it does not exist
    if (! mediaStorageDir.exists()){
        if (! mediaStorageDir.mkdirs()){
            Log.d("MyCameraApp", "failed to create directory");
            return null;
        }
    }

    // Create a media file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    File mediaFile;
    if (type == MEDIA_TYPE_IMAGE){
        mediaFile = new File(mediaStorageDir.getPath() + File.separator +
        "IMG_"+ timeStamp + ".jpg");
    } else if(type == MEDIA_TYPE_VIDEO) {
        mediaFile = new File(mediaStorageDir.getPath() + File.separator +
        "VID_"+ timeStamp + ".mp4");
    } else {
        return null;
    }

    return mediaFile;
}
yushulx
  • 11,695
  • 8
  • 37
  • 64
  • What's problem if my device has not mounted SdCard yet guy? I still use this function good? – Huy Tower Dec 24 '13 at 03:25
  • at least you have interval storage right? the method means you can get the public directory of your devices. some devices may only have internal storage, not all devices have extra sdcard slot like Samsung's devices. So this method can work well – yushulx Dec 24 '13 at 03:31
  • Yes, at least I have internal storage. So your answer did not related to my error. Sorry. – Huy Tower Dec 24 '13 at 04:17