Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with Microphone Permission Request using QMicrophonePermission and info.plist file

Problem with Microphone Permission Request using QMicrophonePermission and info.plist file

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 277 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.
  • S Offline
    S Offline
    SlayH
    wrote on last edited by SlayH
    #1
    QPushButton *record = new QPushButton("RECORD", this);
    connect(record, &QPushButton::clicked, this, [=]()
            {
    QMicrophonePermission microphonePermission;
    
    switch (qApp->checkPermission(microphonePermission)) {
        case Qt::PermissionStatus::Undetermined:
            // Request permission asynchronously
            qApp->requestPermission(microphonePermission, [this]()
                                    {
                // Permission granted, perform action here
                qDebug() << "Microphone permission granted!";
                std::cout << std::endl; std::cout << std::endl; });
            break;
        case Qt::PermissionStatus::Denied:
            // Handle denied permission state appropriately
            qApp->requestPermission(microphonePermission, [this]()
                                    {
                // Permission granted, perform action here
                qDebug() << "Asking permission within the Denied case!";
                std::cout << std::endl; std::cout << std::endl; });
    
            qWarning("Microphone permission is not granted!");
            std::cout << std::endl;
            std::cout << std::endl;
            // Display a message to the user or provide guidance
            break;
        case Qt::PermissionStatus::Granted:
            // Permission already granted, perform action here
            QMediaCaptureSession session;
            QAudioInput audioInput;
            audioInput.device();
            session.setAudioInput(&audioInput);
            QMediaRecorder recorder;
            session.setRecorder(&recorder);
            recorder.setQuality(QMediaRecorder::HighQuality);
            recorder.setOutputLocation(QUrl::fromLocalFile("test.mp3"));
            recorder.record();
            qDebug() << "Recording started!";
            std::cout << std::endl;
            std::cout << std::endl;
            break;
    } });   
    

    The info.plist file is as follow. The 2 last permission are related to the microphone.

    code_text
    

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>English</string>
    <key>CFBundleExecutable</key>
    <string>client</string>
    <key>CFBundleGetInfoString</key>
    <string></string>
    <key>CFBundleIconFile</key>
    <string></string>
    <key>CFBundleIdentifier</key>
    <string></string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleLongVersionString</key>
    <string></string>
    <key>CFBundleName</key>
    <string></string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string></string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string></string>
    <key>CSResourcesFileMapped</key>
    <true/>
    <key>NSHumanReadableCopyright</key>
    <string></string>
    <key>NSMicrophoneUsageDescription</key>
    <string>The microphone is used to record voice memos.</string>
    <key>NSBluetoothAlwaysUsageDescription</key>
    <string>The Bluetooth is used to record voice memos.</string>
    </dict>
    </plist>

    code_text
    

    Hello everyone, I have been trying to grant persmission to use the microphone but in vain. I have used QMicrophonePermission to check the permission and request it if not granted. I have also declared the permission in the info.plist file but nothing works. A little help would be much appreciated from anyone who has a vague idea about it.

    jsulmJ 1 Reply Last reply
    0
    • S SlayH
      QPushButton *record = new QPushButton("RECORD", this);
      connect(record, &QPushButton::clicked, this, [=]()
              {
      QMicrophonePermission microphonePermission;
      
      switch (qApp->checkPermission(microphonePermission)) {
          case Qt::PermissionStatus::Undetermined:
              // Request permission asynchronously
              qApp->requestPermission(microphonePermission, [this]()
                                      {
                  // Permission granted, perform action here
                  qDebug() << "Microphone permission granted!";
                  std::cout << std::endl; std::cout << std::endl; });
              break;
          case Qt::PermissionStatus::Denied:
              // Handle denied permission state appropriately
              qApp->requestPermission(microphonePermission, [this]()
                                      {
                  // Permission granted, perform action here
                  qDebug() << "Asking permission within the Denied case!";
                  std::cout << std::endl; std::cout << std::endl; });
      
              qWarning("Microphone permission is not granted!");
              std::cout << std::endl;
              std::cout << std::endl;
              // Display a message to the user or provide guidance
              break;
          case Qt::PermissionStatus::Granted:
              // Permission already granted, perform action here
              QMediaCaptureSession session;
              QAudioInput audioInput;
              audioInput.device();
              session.setAudioInput(&audioInput);
              QMediaRecorder recorder;
              session.setRecorder(&recorder);
              recorder.setQuality(QMediaRecorder::HighQuality);
              recorder.setOutputLocation(QUrl::fromLocalFile("test.mp3"));
              recorder.record();
              qDebug() << "Recording started!";
              std::cout << std::endl;
              std::cout << std::endl;
              break;
      } });   
      

      The info.plist file is as follow. The 2 last permission are related to the microphone.

      code_text
      

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
      <plist version="1.0">
      <dict>
      <key>CFBundleDevelopmentRegion</key>
      <string>English</string>
      <key>CFBundleExecutable</key>
      <string>client</string>
      <key>CFBundleGetInfoString</key>
      <string></string>
      <key>CFBundleIconFile</key>
      <string></string>
      <key>CFBundleIdentifier</key>
      <string></string>
      <key>CFBundleInfoDictionaryVersion</key>
      <string>6.0</string>
      <key>CFBundleLongVersionString</key>
      <string></string>
      <key>CFBundleName</key>
      <string></string>
      <key>CFBundlePackageType</key>
      <string>APPL</string>
      <key>CFBundleShortVersionString</key>
      <string></string>
      <key>CFBundleSignature</key>
      <string>????</string>
      <key>CFBundleVersion</key>
      <string></string>
      <key>CSResourcesFileMapped</key>
      <true/>
      <key>NSHumanReadableCopyright</key>
      <string></string>
      <key>NSMicrophoneUsageDescription</key>
      <string>The microphone is used to record voice memos.</string>
      <key>NSBluetoothAlwaysUsageDescription</key>
      <string>The Bluetooth is used to record voice memos.</string>
      </dict>
      </plist>

      code_text
      

      Hello everyone, I have been trying to grant persmission to use the microphone but in vain. I have used QMicrophonePermission to check the permission and request it if not granted. I have also declared the permission in the info.plist file but nothing works. A little help would be much appreciated from anyone who has a vague idea about it.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @SlayH Please don't post problem topics in "Announcements" forum! I will move it.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • jsulmJ jsulm moved this topic from Announcements on

      • Login

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