Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Camera not switching to active state in qt6 android
Forum Updated to NodeBB v4.3 + New Features

Camera not switching to active state in qt6 android

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
9 Posts 3 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    iSolve_Tech
    wrote on last edited by
    #1

    I CameraManagerGlobal: Camera 0 facing CAMERA_FACING_BACK state now CAMERA_STATE_OPEN for client no.ablecon.ablemobile API Level 2 User Id 0
    I CameraManagerGlobal: Camera 0 facing CAMERA_FACING_BACK state now CAMERA_STATE_CLOSED for client no.ablecon.ablemobile API Level 2 User Id 0
    I CameraManagerGlobal: Camera 0 facing CAMERA_FACING_BACK state now CAMERA_STATE_OPENING for client no.ablecon.ablemobile API Level 2 User Id 0
    D AbleCenter: isActive false
    D AbleCenter: isAvailable true why the camera is not switching to active state

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You should give more information:

      • Exact Qt version
      • Exact Androïd version
      • Device in use

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • I Offline
        I Offline
        iSolve_Tech
        wrote on last edited by iSolve_Tech
        #3

        @SGaist Qt Version: 6.5.3, Android version: 13, 14, Device: Samsung, Poco, the same code is working for iOS, Windows & particularly on android it's not working.

        For your reference am giving the log here

        I CameraManagerGlobal: Camera 0 facing CAMERA_FACING_BACK state now CAMERA_STATE_CLOSED for client no.ablecon.ablemobile API Level 2 User Id 0
        I CameraManagerGlobal: Camera 0 facing CAMERA_FACING_BACK state now CAMERA_STATE_OPENING for client no.ablecon.ablemobile API Level 2 User Id 0
        I CameraManagerGlobal: Camera 0 facing CAMERA_FACING_BACK state now CAMERA_STATE_OPEN for client no.ablecon.ablemobile API Level 2 User Id 0

        The camera state is not switching to active why?

        J 1 Reply Last reply
        0
        • I iSolve_Tech

          @SGaist Qt Version: 6.5.3, Android version: 13, 14, Device: Samsung, Poco, the same code is working for iOS, Windows & particularly on android it's not working.

          For your reference am giving the log here

          I CameraManagerGlobal: Camera 0 facing CAMERA_FACING_BACK state now CAMERA_STATE_CLOSED for client no.ablecon.ablemobile API Level 2 User Id 0
          I CameraManagerGlobal: Camera 0 facing CAMERA_FACING_BACK state now CAMERA_STATE_OPENING for client no.ablecon.ablemobile API Level 2 User Id 0
          I CameraManagerGlobal: Camera 0 facing CAMERA_FACING_BACK state now CAMERA_STATE_OPEN for client no.ablecon.ablemobile API Level 2 User Id 0

          The camera state is not switching to active why?

          J Offline
          J Offline
          jack_study_qt
          wrote on last edited by
          #4

          @iSolve_Tech Because Android requires permissions, you need to address the permission issue to access the camera. The problem I am currently trying to solve is the recording file saving issue.

          I 1 Reply Last reply
          0
          • J jack_study_qt

            @iSolve_Tech Because Android requires permissions, you need to address the permission issue to access the camera. The problem I am currently trying to solve is the recording file saving issue.

            I Offline
            I Offline
            iSolve_Tech
            wrote on last edited by
            #5

            @jack_study_qt Camera permission & Write external storage permission already there & am asking run time permission. The same code which is working for windows & iOS

            J 4 Replies Last reply
            0
            • I iSolve_Tech

              @jack_study_qt Camera permission & Write external storage permission already there & am asking run time permission. The same code which is working for windows & iOS

              J Offline
              J Offline
              jack_study_qt
              wrote on last edited by
              #6

              @iSolve_Tech If you try setting it up on your phone, you'll notice it's not there; that part requires dynamic requests. Try setting it up directly on your phone without writing any code.

              1 Reply Last reply
              0
              • I iSolve_Tech

                @jack_study_qt Camera permission & Write external storage permission already there & am asking run time permission. The same code which is working for windows & iOS

                J Offline
                J Offline
                jack_study_qt
                wrote on last edited by
                #7

                @iSolve_Tech I'll show you the permissions necessary for running on Android later

                1 Reply Last reply
                0
                • I iSolve_Tech

                  @jack_study_qt Camera permission & Write external storage permission already there & am asking run time permission. The same code which is working for windows & iOS

                  J Offline
                  J Offline
                  jack_study_qt
                  wrote on last edited by
                  #8

                  @iSolve_Tech <uses-feature android:name="android.hardware.camera" android:required="true"/>
                  <uses-permission android:name="android.permission.RECORD_AUDIO"/>
                  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
                  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
                  <uses-permission android:name="android.permission.MANAGE_DOCUMENTS"/>
                  <uses-permission android:name="android.permission.CAMERA" /> ui->setupUi(this);

                  labDuration=new QLabel("录制时间: ");
                  labDuration->setMinimumWidth(120);
                  ui->statusBar->addWidget(labDuration);
                  
                  labFormatInfo=new QLabel("图片分辨率: ");
                  labFormatInfo->setMinimumWidth(150);
                  ui->statusBar->addWidget(labFormatInfo);
                  
                  labInfo=new QLabel("信息");
                  ui->statusBar->addPermanentWidget(labInfo);
                  

                  //1. 发现摄像头
                  QCameraDevice defaultCameraDevice= QMediaDevices::defaultVideoInput();
                  if (defaultCameraDevice.isNull())
                  {
                  QMessageBox::critical(this,"提示","没有发现摄像头");
                  return;
                  }
                  QByteArray defaultCameraID=defaultCameraDevice.id();
                  ui->actStartCamera->setEnabled(true);

                  // disconnect(ui->comboCam_List); //解除与comboCam_List连接的所有槽函数
                  int index=0;
                  for(int i=0; i<QMediaDevices::videoInputs().size(); i++)
                  {
                  QCameraDevice device=QMediaDevices::videoInputs().at(i);
                  if (device.id() == defaultCameraID)
                  {
                  ui->comboCam_List->addItem(device.description()+"(默认)",QVariant::fromValue(device));
                  index=i;
                  }
                  else
                  ui->comboCam_List->addItem(device.description(),QVariant::fromValue(device));
                  }

                  if (ui->comboCam_List->currentIndex() != index)
                      ui->comboCam_List->setCurrentIndex(index);
                  

                  // foreach(QCameraDevice device, QMediaDevices::videoInputs())
                  // {
                  // if (device.isDefault()) //是默认设备
                  // ui->comboCam_List->addItem(device.description()+"(默认)",QVariant::fromValue(device));
                  // else
                  // ui->comboCam_List->addItem(device.description(),QVariant::fromValue(device));
                  // }

                  // ui->comboCam_List->addItem(cameraDevice.description());
                  // showCameraDeviceInfo(&cameraDevice);

                  // ui->comboCam_List->addItem(cameraDevice.description());

                  //2. 创建抓取管理器session和各个设备
                  session = new QMediaCaptureSession(this); //抓取管理器
                  session->setVideoOutput(ui->videoPreview); //设置视频输出组件,用于视频预览
                  //2.1 创建QAudioInput对象,用用音频输入
                  QAudioInput *audioInput=new QAudioInput(this);
                  audioInput->setDevice(QMediaDevices::defaultAudioInput());
                  session->setAudioInput(audioInput); //设置音频输入设备

                  //2.2 创建QCamera对象,用于控制摄像头
                  camera = new QCamera(this); //摄像头
                  camera->setCameraDevice(defaultCameraDevice); //
                  session->setCamera(camera); //为session设置摄像头
                  connect(camera, &QCamera::activeChanged,this, &MainWindow::do_camera_activeChanged);
                  connect(ui->comboCam_List,&QComboBox::currentIndexChanged,
                  this, &MainWindow::do_camera_changed);
                  do_camera_changed(ui->comboCam_List->currentIndex());

                  //2.3 创建QImageCapture对象,用于拍照
                  imageCapture = new QImageCapture(this); //抓图器
                  imageCapture->setQuality(QImageCapture::VeryHighQuality);
                  session->setImageCapture(imageCapture); //为session设置抓图器
                  connect(imageCapture,&QImageCapture::readyForCaptureChanged,
                  this, &MainWindow::do_image_readyForCapture);
                  connect(imageCapture,&QImageCapture::imageCaptured,
                  this,&MainWindow::do_image_captured);
                  connect(imageCapture, &QImageCapture::imageSaved,
                  this, &MainWindow::do_image_saved);

                  soundEffect =new QSoundEffect(this);     //用于播放音效,拍照时的快门声音
                  QString filename=":/sound/images/shutter.wav";
                  soundEffect->setSource(QUrl::fromLocalFile(filename));
                  

                  //2.4 创建QMediaRecorder对象,用于录制视频
                  recorder = new QMediaRecorder(this); //创建recorder
                  session->setRecorder(recorder); //为session设置recorder
                  connect(recorder, &QMediaRecorder::durationChanged,
                  this, &MainWindow::do_recorder_duration);
                  connect(recorder, &QMediaRecorder::recorderStateChanged,
                  this, &MainWindow::do_recorder_stateChanged);
                  connect(recorder, &QMediaRecorder::errorOccurred,
                  this, &MainWindow::do_recorder_error);

                  //3. 视频编码和文件格式,添加到录像设置的下拉列表框里,用于选择
                  QMediaFormat format;
                  foreach(QMediaFormat::VideoCodec codec, format.supportedVideoCodecs(QMediaFormat::Encode))
                  ui->comboVideo_Codec->addItem(QMediaFormat::videoCodecDescription(codec),
                  QVariant::fromValue(codec));
                  foreach(QMediaFormat::FileFormat fileFormat, format.supportedFileFormats(QMediaFormat::Encode))
                  ui->comboVideo_FileFormat->addItem(QMediaFormat::fileFormatDescription(fileFormat),
                  QVariant::fromValue(fileFormat));

                  1 Reply Last reply
                  0
                  • I iSolve_Tech

                    @jack_study_qt Camera permission & Write external storage permission already there & am asking run time permission. The same code which is working for windows & iOS

                    J Offline
                    J Offline
                    jack_study_qt
                    wrote on last edited by
                    #9

                    @iSolve_Tech The real challenge of your program is how to save video recordings on Android. Opening the camera is not an issue! I couldn't find any usable QT6 APIs for this purpose, so in the end, I had to resort to calling the native Android API to allow users to specify the destination and file name for saving!

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved