Auto Focus using Android Camera Plugin - is it possible?

The title says it all really.

I’m using the built-in Android Camera Player plugin (version 2.0 , UE 4.21) and can stream the backfacing camera through to a Media Texture and display it at runtime but it’s kind of pointless as it’s out of focus.
Does anyone know how to enable android’s android.hardware.camera.autofocus feature via this plugin? Or any other way?

I found an old plugin here which mentions being able to edit an xml file in the plugin to enable it but that’s a 3rd party plugin and it won’tr compile for recent versions of the engine.

Any ideas?

I could use the ARCore plugin but it’s not compatible on the device/s I need it for.

Thanks

That old plugin you mention. Should still work for recent versions of the engine. Can I ask the difficulties that you are having?

Well maybe it is late but it can help other people who face same problem. I’ve solved android camera focus problem. There is CameraPlayer14.java file at this folder “C:\Program Files\Epic Games\UE_X.XX\Engine\Plugins\Media\AndroidCamera\Source\AndroidCamera\Java\src\com\epicgames\ue4”. You should add line “param.setFocusMode(“continuous-picture”);” after line 520. And this should add auto focus. I think this must be added to official plugin.

2 Likes

Thanks vristok, what is the the compile procedure?

It compiles during android packaging. Also I had a problem with low FPS. I solved it changing the same CameraPlayer14.java file at lines 516 and 517. I changed these lines on:
width = previewSizes.get(0).width;
height = previewSizes.get(0).height;

P.S.
You have to consider that you should make this changes every time you install new engine version, so it is a good idea to save changed file anywhere.

2 Likes

UE5.1 packages but android app crashes on Galaxy S21 when I chose back camera.
Also I tried this after yours.
param.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);

edit:
Tried this (and alose with else if)

		List<String> focusModes = param.getSupportedFocusModes();
		if (focusModes.contains(param.FOCUS_MODE_CONTINUOUS_VIDEO)) 
		{
			param.setFocusMode(param.FOCUS_MODE_CONTINUOUS_VIDEO);
		}

		if (focusModes.contains(param.FOCUS_MODE_CONTINUOUS_PICTURE))
		{
			param.setFocusMode(param.FOCUS_MODE_CONTINUOUS_PICTURE);
		}

		if (focusModes.contains(param.FOCUS_MODE_FIXED))
		{
			param.setFocusMode(param.FOCUS_MODE_FIXED);
		}

		if (focusModes.contains(param.FOCUS_MODE_INFINITY))
		{
			param.setFocusMode(param.FOCUS_MODE_INFINITY);
		}

I don’t get any crash but also there is no visible focus.

1 Like