1

I have a Sony xperia Z with android 4.4.2 in which I have an app that can take photos.

It has a TextureView for previewing, so I have a line saying

camera.setPreviewTexture(preview_texture_view.getSurfaceTexture());

then later...

camera.startPreview();

The app now displays a continuous preview of what the camera sees. I can then press a button and the following gets executed:

camera.takePicture(mShutterCallback, mPictureCallbackRaw, this);    

A picture is taken, and saved. Also the previewing is still active (which is exactly what I want).

All well and good so far. But the problem occurs when I try and run the exact same app on a prototype device I have, which is running Android 4.3. I see the preview ok, and when I press my button, the photo is taken and saved ok. But the preview is now frozen. The program has not crashed. takePicture() returned without any exception.

My suspicion was that perhaps, in different versions of Android it may be defined behaviour that takePicture() somehow resets(?) the camera after it is done - perhaps it is some design change that made between 4.3 and 4.4.1, or perhaps different hardware could make a difference.

Has anyone come across a similar issue? If so how was it solved?

EDIT: I tried putting camera.startPreview(); inside the onPictureTaken method of my PictureCallback, but it immediately crashes with: RuntimException startPreview failed.

Mick
  • 8,284
  • 22
  • 81
  • 173
  • Having the exact same issue here with the Xperia Z3, worked fine on Xperia Z2, Xperia Z1, Xperia ZR & Xperia T2 Ultra... The preview is frozen but it can continue to take pictures even after restarting the preview, just frozen – Pete Nov 09 '14 at 16:36
  • Sort of fixed after using the answer to this question, extremely annoying though: http://stackoverflow.com/questions/8257318/surfaceview-with-camera-preview-is-not-destroyed – Pete Nov 09 '14 at 17:03

1 Answers1

0

You need to restart the preview yourself, such as from onPictureTaken(). The preview stops automatically with takePicture(), so you do not have to manually stop the preview, but you do have to manually restart it.

As to why your Xperia Z is behaving as it is, you would have to ask SONY.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • @Mick: Talk to whoever provided you with the prototype device, asking them why their camera implementation has issues. You are also welcome to try [my camera library](http://github.com/commonsguy/cwac-camera) and its demo app, which handles restarting the preview properly on dozens of devices. If your prototype device exhibits the same problem, then the device itself is behaving badly. – CommonsWare Aug 22 '14 at 16:30