Details
-
Bug
-
Resolution: Done
-
P2: Important
-
6.2.0
-
None
-
Android 11.0
-
-
d805e2c245e1722e350fcfebabec42fbddd0b22b (qt/qtmultimedia/dev) 2b741a5561bae8eee984891ec0728c80d95b9cb1 (qt/qtmultimedia/6.2)
-
2021wk44POAndroid&Mobile
Description
Not sure if this should work at all, but the workaround I have is ugly.
Example showing the problem:
import QtQuick import QtQuick.Window import QtMultimedia import QtQuick.Controls Window { width: 640 height: 480 visible: true title: qsTr("Example fails first") Component{ id: startPage Button{ text: "Open camera" onClicked: stackView.push( cameraPage ) } } Component{ id: cameraPage Item{ VideoOutput{ id: viewFinder anchors.fill: parent } CaptureSession{ id: captureSession camera: Camera{} videoOutput: viewFinder } Button{ text: "Back" anchors.left: parent.left anchors.bottom: parent.bottom onClicked: { captureSession.camera.stop(); stackView.pop(); } } Component.onCompleted: captureSession.camera.start(); } } StackView{ id: stackView initialItem: startPage anchors.fill: parent } }
- Open app in android
- Press "Open camera"
- Grant camera permission
- The camera preview does not show in the VideoOutput
- Press "Back"
- Press "Open camera"
- The camera preview does show in the VideoOutput
Ugly workaround:
import QtQuick import QtQuick.Window import QtMultimedia import QtQuick.Controls Window { width: 640 height: 480 visible: true title: qsTr("Example ugly workaround") Component{ id: startPage Button{ text: "Open camera" onClicked: stackView.push( cameraPage ) } } Component{ id: cameraPage Item{ VideoOutput{ id: viewFinder anchors.fill: parent } CaptureSession{ id: captureSession camera: Camera{} videoOutput: viewFinder } Connections{ target: captureSession.camera function onActiveChanged(){ if( captureSession.camera.active ) cameraStarter.running = false; } } Button{ text: "Back" anchors.left: parent.left anchors.bottom: parent.bottom onClicked: { captureSession.camera.stop(); stackView.pop(); } } Timer{ id: cameraStarter running: true interval: 250 repeat: true onTriggered: captureSession.camera.start() } } } StackView{ id: stackView initialItem: startPage anchors.fill: parent } }
In this basic example without StackView it just works:
import QtQuick import QtQuick.Window import QtMultimedia import QtQuick.Controls Window { width: 640 height: 480 visible: true title: qsTr("Example works") VideoOutput{ id: viewFinder anchors.fill: parent } CaptureSession{ id: captureSession camera: Camera{} videoOutput: viewFinder } Component.onCompleted: captureSession.camera.start(); }
Maybe related to https://bugreports.qt.io/browse/QTBUG-96346 ?