Hi,

Re -  I imagine I'm doing something horribly wrong,

Well yes, particularly for this code, calling methods on a null object ??? 
 -

 if (mCamera == null) {
            mCamera.setPreviewDisplay(holder); ...


I'd suggest waiting a little after starting the Camera Preview before 
initiating a call to autofocus, say 500ms to 1 second, this is to give the 
camera some time to settle after it has just been opened.


I'd also suggest that you do this asynchronously, eg -


// Need handler for callbacks to the UI thread
final Handler mHandler = new Handler();


mHandler.postDelayed(new Runnable()
{
   @Override
   public void run()
   {
      doAutoFocus(..
   }
             
}, 500 );


Regards



On Thursday, March 24, 2016 at 12:11:11 PM UTC+11, David Karr wrote:
>
> On Wednesday, March 23, 2016 at 12:06:47 AM UTC-7, gjs wrote:
>
> Hi,
>
> For the focus / fuzzy issue try initiating auto focusing of the camera 
> before you start recording your video -
>
>
> http://developer.android.com/reference/android/hardware/Camera.html#autoFocus(android.hardware.Camera.AutoFocusCallback)
>
>
> Thanks for replying.  I imagine I'm doing something horribly wrong, but 
> I'm not getting much from this.  I made a change in my "CameraPreview" 
> class to add this call, in the "surfaceCreated()" method.  It now looks 
> like this, which will immediately look odd:
>
> public void surfaceCreated(SurfaceHolder holder) {
>     try {
>         // create the surface and start camera preview
>         if (mCamera == null) {
>             mCamera.setPreviewDisplay(holder);
>             mCamera.startPreview();
>             mCamera.autoFocus(new Camera.AutoFocusCallback() {
>                 @Override
>                 public void onAutoFocus(boolean success, Camera camera) {
>                     Log.d(VIEW_LOG_TAG, "Completed autofocus setup: success[" 
> + success + "]");
>                 }
>             });
>         }
>         else {
>             mCamera.setPreviewDisplay(holder);
>             mCamera.startPreview();
>             mCamera.autoFocus(new Camera.AutoFocusCallback() {
>                 @Override
>                 public void onAutoFocus(boolean success, Camera camera) {
>                     Log.d(VIEW_LOG_TAG, "Completed autofocus setup: success[" 
> + success + "]");
>                 }
>             });
>         }
>     } catch (IOException e) {
>         Log.d(VIEW_LOG_TAG, "Error setting camera preview: " + 
> e.getMessage());
>     }
> }
>
>
>
>
> Yes, I'm calling that block for both the null and !null case.  I did that 
> because when I ran in the debugger, I saw that it never got into the "== 
> null" block, so I'm experimenting with calling it when it's not null.  In 
> any case, it calls the "autofocus()" method, but the "onAutoFocus()" method 
> is never called.  At one point when it retrieves the "Camera.Parameters" 
> object, I added a log statement for "focusMode", and it prints "auto".  And 
> it doesn't appear to be focusing.
>  
>
>
> - you can also do this whilst the video is recording as well, although you 
> will have periods of a few seconds where focus is lost before being 
> regained.
>
> Note sure about upside down video, I suspect this not the video recording 
> but perhaps some Camera Preview rotation mismatch / issue in your 
> CameraPreview class ? Compare the Camera Preview orientation in your app 
> vs when you use the default Camera App. (NOTE also that Nexus 5X has some 
> wrong camera preview orientation issues...)
>
> Regards
>
>
>
> On Wednesday, March 23, 2016 at 3:41:02 PM UTC+11, David Karr wrote:
>
> I've assembled a relatively small camcorder app. It only does what I need 
> it to do.  I assembled it from sample code, and some people on this forum 
> have helped me fix some of the problems with it, although some of the 
> details of interfacing with the camera are beyond me.
>
> After some usage of it, I've realized there are two problems with it:
>
> * Although the preview display is right-side up, the resulting stored 
> video is upside down.  This isn't a huge deal, as I later process this with 
> another app that lets me rotate it till its right-side up, but it's still 
> an annoyance, especially when previewing many videos to see which ones I 
> want to use.
>
> * The video it produces is just fuzzy, or out of focus.  I don't know 
> whether this is the nature of video vs. still images or whether I'm not 
> doing something I should be doing.  Is there some autofocus feature of the 
> camcorder that I'm not taking advantage of?
>
> I'd appreciate any useful advice on this.
>
> I'll provide here the entire Activity class.
>
> package com.integralsoftware.videograbber;
>
> import android.content.Intent;
> import android.media.AudioFormat;
> import android.media.AudioManager;
> import android.media.AudioTrack;
> import android.media.MediaScannerConnection;
> import android.net.Uri;
> import android.os.Bundle;
> import android.os.Environment;
> import android.util.Log;
> import android.view.View;
>
> import java.io.File;
> import java.io.IOException;
> import java.text.SimpleDateFormat;
> import java.util.Date;
>
> import android.app.Activity;
> import android.content.Context;
> import android.content.pm.PackageManager;
> import android.hardware.Camera;
> import android.hardware.Camera.CameraInfo;
> import android.media.MediaRecorder;
> import android.view.View.OnClickListener;
> import android.view.WindowManager;
> import android.view.animation.AlphaAnimation;
> import android.view.animation.Animation;
> import android.widget.Button;
> import android.widget.LinearLayout;
> import android.widget.TextView;
> import android.widget.Toast;
>
> public class VideoGrabberActivity extends Activity {
>     private Camera          mCamera;
>     private CameraPreview   mPreview;
>     private MediaRecorder   mediaRecorder;
>     private Button          capture;
>     private Context         myContext;
>     private LinearLayout    cameraPreview;
>     private TextView        countdownText;
>     private String          outputFilePath;
>     private SimpleDateFormat    simpleDateFormat    = new SimpleDateFormat
> ("yyyyMMdd_HHmmss");
>
>     private static final String VG  = "VideoGrabber";
>
>     private static final int    RS_WAITING      = 0;
>     private static final int    RS_COUNTING     = 1;
>     private static final int    RS_RECORDING    = 2;
>
>     private int recordingState  = RS_WAITING;
>
>     @Override
>     public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         setContentView(R.layout.activity_video_grabber);
>         getWindow().addFlags(WindowManager.LayoutParams.
> FLAG_KEEP_SCREEN_ON);
>         countdownText   = (TextView) findViewById(R.id.countdown_text);
>         myContext = this;
>         initialize();
>     }
>
>
>     private int findBackFacingCamera() {
>         int cameraId = -1;
>         int numberOfCameras = Camera.getNumberOfCameras();
>         for (int i = 0; i < numberOfCameras; i++) {
>             CameraInfo info = new CameraInfo();
>             Camera.getCameraInfo(i, info);
>             if (info.facing == CameraInfo.CAMERA_FACING_BACK) {
>                 cameraId = i;
>                 break;
>             }
>
> ...

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/3c3c55fc-50c9-45f2-9298-498d38c96306%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to