SteveTJS
SteveTJS

Reputation: 705

Android QML application, Camera and its settings putting application background and foreground

I have an android QML application (QML 5.12.10, ndk r21e, api 29). I create a simple Camera with the following code:

Camera { id: camera
  position: Camera.BackFace
  digitalZoom: 1.6

  Component.onCompleted:{
    console.info("INFODEBUG Component.onCompleted camera.cameraState " + camera.cameraState 
    + " camera.cameraStatus " + camera.cameraStatus)        
  }
  
  onCameraStateChanged: {
    console.info("INFODEBUG onCameraStateChanged: " + camera.cameraState)
  }

  onCameraStatusChanged: {
    console.info("INFODEBUG onCameraStatusChanged: " + camera.cameraStatus)
  }
}

VideoOutput { id: videoOutput
    source: camera
    anchors.fill: parent
}

The camera video is well displayed and the zoom is OK.

The problem is when I pass the application in background, so I return to my device system screen, and then I put back the application to foreground: the digital zoom is not applied anymore.

Here is the ouput I get:

-when I open the application:

INFODEBUG onCameraStateChanged: 2 (Camera.ActiveState)
INFODEBUG Component.onCompleted camera.cameraState 2 (Camera.ActiveState) camera.cameraStatus 1 (Camera.UnloadedStatus)
INFODEBUG onCameraStatusChanged: 2 (Camera.LoadingStatus)
INFODEBUG onCameraStatusChanged: 4 (Camera.LoadedStatus)
INFODEBUG onCameraStatusChanged: 6 (Camera.StartingStatus)
INFODEBUG onCameraStatusChanged: 8 (Camera.ActiveStatus)

-when the application is sent to background:

INFODEBUG onCameraStatusChanged: 7 (Camera.StoppingStatus)
INFODEBUG onCameraStatusChanged: 3 (Camera.UnloadingStatus)
INFODEBUG onCameraStatusChanged: 1 (Camera.UnloadedStatus)
INFODEBUG onCameraStateChanged: 0 (Camera.UnloadedState)

-when I put back the application to foreground:

INFODEBUG onCameraStatusChanged: 2 (Camera.LoadingStatus)
INFODEBUG onCameraStatusChanged: 4 (Camera.LoadedStatus)
INFODEBUG onCameraStatusChanged: 6 (Camera.StartingStatus)
INFODEBUG onCameraStatusChanged: 8 (Camera.ActiveStatus)

What I noticed is that the cameraState stays to 0 (Camera.UnloadedState) when the application is put back to foreground, which does not seem normal, but if I log out the digital zoom, it is equal to 1.6. So I think that UnloadedState prevents the camera from initializing its settings correctly. I tried forcing it to state Camera.ActiveState but it does not change anything. The state is set back to UnloadedState when the application is completely back to foreground.

So how to put back camera settings correctly when the application goes from background to foreground?

Upvotes: 0

Views: 30

Answers (0)

Related Questions