I have a unity project and I use a Android (java) plugin to get camera data. I draw this on a TextureView. I want to hide/show this view when I press a button in unity. But my app crashes when I setVisibility
onCreate
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//Reset data
ResetData();
//Create camera preview
_camPreview = new CameraPreview();
//Create texture view
TextureView texView = new TextureView(this);
//Initialize camera texutre
_camPreview.Init(texView);
//Add the texture view to unity
UnityPlayer.currentActivity.addContentView(texView, new FrameLayout.LayoutParams(400, 400));
}
Camera Preview class:
public void Init(TextureView texView)
{
//Save texture view
_TextureView = texView;
//Let this class listen to events of the surface
_TextureView.setSurfaceTextureListener(this);
}
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
{
//Get camera
_camera = Camera.open();
_camera.setDisplayOrientation(90);
//Set texture view data
_TextureView.setLayoutParams(new FrameLayout.LayoutParams(425, 425, Gravity.CENTER));
_TextureView.setTranslationY(-70);
//Set dummy texture
try {
_camera.setPreviewTexture(surface);
}
catch (IOException e)
{
Log.e("Unity", "Error surface");
}
//Get parameters
Camera.Parameters parameters = _camera.getParameters();
//Set JPEG
parameters.setPreviewFormat(ImageFormat.JPEG);
//Set image size
parameters.setPreviewSize(480, 320);
//Set new parameters
_camera.setParameters(parameters);
}
public void HideVideo()
{
//Hide view
_TextureView.setVisibility(View.INVISIBLE);
}
Is there an extra function I need to call, or may I only call it on certain times?
None of these thins work, they all make my app crash.
_TextureView.setVisibility(View.INVISIBLE);
_TextureView.setActivated(false);
_TextureView.setAlpha(0);
_TextureView.setTranslationY(-1000);