Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-97610

Android - QML Camera does not work at first after granting permission

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 6.3.0 Alpha, 6.2
    • 6.2.0
    • Multimedia
    • None
    • Android 11.0
    • Android
    • 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
          }
      }
      
      1. Open app in android
      2. Press "Open camera"
      3. Grant camera permission
      4. The camera preview does not show in the VideoOutput
      5. Press "Back"
      6. Press "Open camera"
      7. 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 ?

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            samuelmira Samuel Mira
            Marscho Marscho
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes