Fix/workaround bogus error in Android samples running on Android 4.1.1

This commit is contained in:
Andrey Kamaev 2012-08-23 19:17:51 +04:00
parent eaf75dbc95
commit 4aa03d4b2b
4 changed files with 33 additions and 22 deletions

View File

@ -25,6 +25,7 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
private byte[] mFrame; private byte[] mFrame;
private boolean mThreadRun; private boolean mThreadRun;
private byte[] mBuffer; private byte[] mBuffer;
private SurfaceTexture mSf;
public SampleViewBase(Context context) { public SampleViewBase(Context context) {
@ -43,16 +44,17 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
} }
public void setPreview() throws IOException { public void setPreview() throws IOException {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mCamera.setPreviewTexture( new SurfaceTexture(10) ); mSf = new SurfaceTexture(10);
mCamera.setPreviewTexture( mSf );
}
else else
mCamera.setPreviewDisplay(null); mCamera.setPreviewDisplay(null);
} }
public boolean openCamera() { public boolean openCamera() {
Log.i(TAG, "openCamera"); Log.i(TAG, "openCamera");
releaseCamera();
mCamera = Camera.open(); mCamera = Camera.open();
if(mCamera == null) { if(mCamera == null) {
Log.e(TAG, "Can't open camera!"); Log.e(TAG, "Can't open camera!");
@ -125,15 +127,15 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
mFrame = new byte [size]; mFrame = new byte [size];
mCamera.addCallbackBuffer(mBuffer); mCamera.addCallbackBuffer(mBuffer);
/* Notify that the preview is about to be started and deliver preview size */
onPreviewStarted(params.getPreviewSize().width, params.getPreviewSize().height);
try { try {
setPreview(); setPreview();
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "mCamera.setPreviewDisplay/setPreviewTexture fails: " + e); Log.e(TAG, "mCamera.setPreviewDisplay/setPreviewTexture fails: " + e);
} }
/* Notify that the preview is about to be started and deliver preview size */
onPreviewStarted(params.getPreviewSize().width, params.getPreviewSize().height);
/* Now we can start a preview */ /* Now we can start a preview */
mCamera.startPreview(); mCamera.startPreview();
} }

View File

@ -25,6 +25,7 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
private byte[] mFrame; private byte[] mFrame;
private boolean mThreadRun; private boolean mThreadRun;
private byte[] mBuffer; private byte[] mBuffer;
private SurfaceTexture mSf;
public SampleViewBase(Context context) { public SampleViewBase(Context context) {
@ -43,8 +44,10 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
} }
public void setPreview() throws IOException { public void setPreview() throws IOException {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mCamera.setPreviewTexture( new SurfaceTexture(10) ); mSf = new SurfaceTexture(10);
mCamera.setPreviewTexture( mSf );
}
else else
mCamera.setPreviewDisplay(null); mCamera.setPreviewDisplay(null);
} }
@ -124,15 +127,15 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
mFrame = new byte [size]; mFrame = new byte [size];
mCamera.addCallbackBuffer(mBuffer); mCamera.addCallbackBuffer(mBuffer);
/* Notify that the preview is about to be started and deliver preview size */
onPreviewStarted(params.getPreviewSize().width, params.getPreviewSize().height);
try { try {
setPreview(); setPreview();
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "mCamera.setPreviewDisplay/setPreviewTexture fails: " + e); Log.e(TAG, "mCamera.setPreviewDisplay/setPreviewTexture fails: " + e);
} }
/* Notify that the preview is about to be started and deliver preview size */
onPreviewStarted(params.getPreviewSize().width, params.getPreviewSize().height);
/* Now we can start a preview */ /* Now we can start a preview */
mCamera.startPreview(); mCamera.startPreview();
} }

View File

@ -24,6 +24,7 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
private byte[] mFrame; private byte[] mFrame;
private boolean mThreadRun; private boolean mThreadRun;
private byte[] mBuffer; private byte[] mBuffer;
private SurfaceTexture mSf;
public SampleViewBase(Context context) { public SampleViewBase(Context context) {
@ -42,8 +43,10 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
} }
public void setPreview() throws IOException { public void setPreview() throws IOException {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mCamera.setPreviewTexture( new SurfaceTexture(10) ); mSf = new SurfaceTexture(10);
mCamera.setPreviewTexture( mSf );
}
else else
mCamera.setPreviewDisplay(null); mCamera.setPreviewDisplay(null);
} }
@ -123,15 +126,15 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
mFrame = new byte [size]; mFrame = new byte [size];
mCamera.addCallbackBuffer(mBuffer); mCamera.addCallbackBuffer(mBuffer);
/* Notify that the preview is about to be started and deliver preview size */
onPreviewStarted(params.getPreviewSize().width, params.getPreviewSize().height);
try { try {
setPreview(); setPreview();
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "mCamera.setPreviewDisplay/setPreviewTexture fails: " + e); Log.e(TAG, "mCamera.setPreviewDisplay/setPreviewTexture fails: " + e);
} }
/* Notify that the preview is about to be started and deliver preview size */
onPreviewStarted(params.getPreviewSize().width, params.getPreviewSize().height);
/* Now we can start a preview */ /* Now we can start a preview */
mCamera.startPreview(); mCamera.startPreview();
} }

View File

@ -24,6 +24,7 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
private byte[] mFrame; private byte[] mFrame;
private boolean mThreadRun; private boolean mThreadRun;
private byte[] mBuffer; private byte[] mBuffer;
private SurfaceTexture mSf;
public SampleViewBase(Context context) { public SampleViewBase(Context context) {
@ -42,8 +43,10 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
} }
public void setPreview() throws IOException { public void setPreview() throws IOException {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mCamera.setPreviewTexture( new SurfaceTexture(10) ); mSf = new SurfaceTexture(10);
mCamera.setPreviewTexture( mSf );
}
else else
mCamera.setPreviewDisplay(null); mCamera.setPreviewDisplay(null);
} }
@ -123,15 +126,15 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
mFrame = new byte [size]; mFrame = new byte [size];
mCamera.addCallbackBuffer(mBuffer); mCamera.addCallbackBuffer(mBuffer);
/* Notify that the preview is about to be started and deliver preview size */
onPreviewStarted(params.getPreviewSize().width, params.getPreviewSize().height);
try { try {
setPreview(); setPreview();
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "mCamera.setPreviewDisplay/setPreviewTexture fails: " + e); Log.e(TAG, "mCamera.setPreviewDisplay/setPreviewTexture fails: " + e);
} }
/* Notify that the preview is about to be started and deliver preview size */
onPreviewStarted(params.getPreviewSize().width, params.getPreviewSize().height);
/* Now we can start a preview */ /* Now we can start a preview */
mCamera.startPreview(); mCamera.startPreview();
} }