@SGaist
Thanks for you reply. The only way to create what I need - using Android functions directly and I must forgot about crossplatform for my app (if you want to use, for example, hardware acceleration or something).
The code bellow is the main class (java, for use with QAndroidJniObject), that draws camera preview, using hardware:
import org.qtproject.qt5.android.bindings.QtApplication;
import org.qtproject.qt5.android.bindings.QtActivity;
import android.hardware.Camera;
import android.media.MediaCodec;
import android.media.MediaCodecInfo;
import android.media.MediaFormat;
import android.media.MediaMuxer;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.graphics.SurfaceTexture;
import android.view.TextureView.SurfaceTextureListener;
import android.view.TextureView;
import android.view.Gravity;
import android.widget.FrameLayout;
import android.os.Bundle;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
public class CameraAndroid extends QtActivity implements SurfaceTextureListener {
private static NotificationManager notificationManager;
private static Notification.Builder notificationBuilder;
private static CameraAndroid cameraAndroid;
public CameraAndroid() {
cameraAndroid = this;
}
private static MediaCodec mediaCodec;
private static TextureView textureView;
private static Camera camera;
static int encWidth = 640, encHeight = 480;
public static int start() {
// Camera not started yet
if(camera == null) {
Camera.CameraInfo info = new Camera.CameraInfo();
// Set front facing camera by default
int numCameras = Camera.getNumberOfCameras();
for (int i = 0; i < numCameras; i++) {
Camera.getCameraInfo(i, info);
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
camera = Camera.open(i);
break;
}
}
if (camera == null) {
camera = Camera.open();
}
if (camera == null) return 9001;
Camera.Parameters params = camera.getParameters();
Camera.Size cameraSize = params.getPreferredPreviewSizeForVideo();
for (Camera.Size size : params.getSupportedPreviewSizes()) {
if (size.width == encWidth && size.height == encHeight) {
params.setPreviewSize(encWidth, encHeight);
break;
}
}
// New camera preview size
if (cameraSize != null) {
params.setPreviewSize(cameraSize.width, cameraSize.height);
}
camera.setParameters(params);
textureView.setLayoutParams(new FrameLayout.LayoutParams(camera.getParameters().getPreviewSize().width, camera.getParameters().getPreviewSize().height, Gravity.CENTER));
}
return 0;
}
public static int stop() {
if (camera != null) {
camera.stopPreview();
camera.release();
camera = null;
}
return 0;
}
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
textureView = new TextureView(this);
textureView.setSurfaceTextureListener(this);
setContentView(textureView); // <------------------------- Draws on all entire screen :((((
}
@Override public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
try {
if(start() == 0) {
camera.setPreviewTexture(surface);
camera.startPreview();
}
} catch (IOException ioe) {
return 9002;
}
}
@Override public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
}
@Override public void onSurfaceTextureUpdated(SurfaceTexture surface) {}
@Override public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
stop();
return true;
}
}
But now, I can't see QML elements of my app! :(( Is it possible to draw QML elements over/above TextureView, change draw order or something? What I must to do?
Many thanks!