私はonPreviewFrame(byte[] data, Camera camera)
Androidで作業しています。onPreviewFrame 内で、いくつかの画像処理を行います。onPreviewFrame 内のポイントで、プレビューを停止し (if ステートメントでそのポイントを知っています)、音 (おそらく電話の着信音) を再生したいと考えています。プレビューで音を鳴らすことはできないと思います。
onPreviewFrame を終了するにはどうすればよいですか? また、サウンドを再生するためのコードはどこに追加すればよいですか?
それはSurface Destroyedですか?
これが私のコードです:
public class MyCameraPreview extends Activity {
private Preview mPreview;
public TextView results;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Hide the window title.
requestWindowFeature(Window.FEATURE_NO_TITLE);
// Create our Preview view and set it as the content of our activity.
mPreview = new Preview(this);
setContentView(mPreview);
}
}
class Preview extends SurfaceView implements SurfaceHolder.Callback, PreviewCallback {
SurfaceHolder mHolder;
Camera mCamera;
public TextView results;
public TextView txt;
private Parameters parameters;
//this variable stores the camera preview size
private Size previewSize;
//this array stores the pixels as hexadecimal pairs
private int[] pixels;
public int[] argb8888;
Preview(Context context) {
super(context);
// Install a SurfaceHolder.Callback so we get notified when the
// underlying surface is created and destroyed.
mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
public void surfaceCreated(SurfaceHolder holder) {
// The Surface has been created, acquire the camera and tell it where
// to draw.
mCamera = Camera.open();
try {
mCamera.setPreviewDisplay(holder);
//sets the camera callback to be the one defined in this class
mCamera.setPreviewCallback(this);
parameters = mCamera.getParameters();
parameters.setZoom(parameters.getMaxZoom());
mCamera.setParameters(parameters);
parameters = mCamera.getParameters();
previewSize = parameters.getPreviewSize();
pixels = new int[previewSize.width * previewSize.height];
} catch (IOException exception) {
mCamera.release();
mCamera = null;
// TODO: add more exception handling logic here
}
}
public void surfaceDestroyed(SurfaceHolder holder) {
// Surface will be destroyed when we return, so stop the preview.
// Because the CameraDevice object is not a shared resource, it's very
// important to release it when the activity is paused.
mCamera.stopPreview();
mCamera.release();
mCamera = null;
}
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
// Now that the size is known, set up the camera parameters and begin
// the preview.
parameters.setPreviewSize(w, h);
//set the camera's settings
mCamera.setParameters(parameters);
mCamera.startPreview();
}
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
Do some image processing.
If condition == true {
Exit the preview and then play the ringtone and exit the application.
}
}