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. QAudioOutput::setDevice seems not work on mac
Forum Update on Monday, May 27th 2025

QAudioOutput::setDevice seems not work on mac

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 2 Posters 646 Views
  • 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.
  • C Offline
    C Offline
    cwlmyjm
    wrote on last edited by
    #1

    I am using QMediaPlayer to play wav on mac mini with a QAudioOutput, and I want the wav play on my headset rather then build-in speaker. The following is my code:

        // create mediaPlayer and audioOutput
        m_mediaPlayer = new QMediaPlayer(this);
        m_audioOutput = new QAudioOutput(this);
        m_audioOutput->setVolume(1);
        m_mediaPlayer->setAudioOutput(m_audioOutput);
    
       // set soure and loop
        m_mediaPlayer->setSource(qrc:/audio_calling.wav);
        m_mediaPlayer->setLoops(20);
    
        // pause and stop before change auidoDevice
        m_mediaPlayer->pause();
        m_mediaPlayer->stop();
    
        QAudioDevice target_device;
        QList<QAudioDevice> devices = QMediaDevices::audioOutputs();
        for(const auto& device : devices)
        {
           // find my device and set to target_device
        }
        m_audioOutput->setDevice(target_device);
         // replay
         m_mediaPlayer->play();
    

    But the audio still play on build-in speaker.

    I use qt6.4.3 on M1 mac with macos ventura 13.3.1

    Axel SpoerlA 1 Reply Last reply
    0
    • C cwlmyjm

      I am using QMediaPlayer to play wav on mac mini with a QAudioOutput, and I want the wav play on my headset rather then build-in speaker. The following is my code:

          // create mediaPlayer and audioOutput
          m_mediaPlayer = new QMediaPlayer(this);
          m_audioOutput = new QAudioOutput(this);
          m_audioOutput->setVolume(1);
          m_mediaPlayer->setAudioOutput(m_audioOutput);
      
         // set soure and loop
          m_mediaPlayer->setSource(qrc:/audio_calling.wav);
          m_mediaPlayer->setLoops(20);
      
          // pause and stop before change auidoDevice
          m_mediaPlayer->pause();
          m_mediaPlayer->stop();
      
          QAudioDevice target_device;
          QList<QAudioDevice> devices = QMediaDevices::audioOutputs();
          for(const auto& device : devices)
          {
             // find my device and set to target_device
          }
          m_audioOutput->setDevice(target_device);
           // replay
           m_mediaPlayer->play();
      

      But the audio still play on build-in speaker.

      I use qt6.4.3 on M1 mac with macos ventura 13.3.1

      Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote on last edited by Axel Spoerl
      #2

      @cwlmyjm
      Good morning,
      What is the audio setup? An external audio device? Or just an external speaker?
      How many devices does the program find?
      Can you debug all devices found and post them here?
      Just add qDebug() << devices; above the for loop.
      Cheers Axel

      Software Engineer
      The Qt Company, Oslo

      C 1 Reply Last reply
      0
      • Axel SpoerlA Axel Spoerl

        @cwlmyjm
        Good morning,
        What is the audio setup? An external audio device? Or just an external speaker?
        How many devices does the program find?
        Can you debug all devices found and post them here?
        Just add qDebug() << devices; above the for loop.
        Cheers Axel

        C Offline
        C Offline
        cwlmyjm
        wrote on last edited by
        #3

        @Axel-Spoerl sorry for the late reply, I find I cannot directly print the devices, so I write a loop to print id, description, isDefault and mode.
        POPO20231219-122654.png

        and the following is my audio setting
        POPO20231219-122505.png

        I plugin a usb sound card, the default output is Mac mini speaker and I want to play sound on GVAUDIO, but after I call setDevice, the sound still play on Mac mini speaker.

        Axel SpoerlA 1 Reply Last reply
        0
        • C cwlmyjm

          @Axel-Spoerl sorry for the late reply, I find I cannot directly print the devices, so I write a loop to print id, description, isDefault and mode.
          POPO20231219-122654.png

          and the following is my audio setting
          POPO20231219-122505.png

          I plugin a usb sound card, the default output is Mac mini speaker and I want to play sound on GVAUDIO, but after I call setDevice, the sound still play on Mac mini speaker.

          Axel SpoerlA Offline
          Axel SpoerlA Offline
          Axel Spoerl
          Moderators
          wrote on last edited by
          #4

          @cwlmyjm
          Hi,
          Thanks for the analysis. What happens, if you play from the Mac directly, without Qt, and you select the USB device for output?

          Software Engineer
          The Qt Company, Oslo

          C 2 Replies Last reply
          0
          • Axel SpoerlA Axel Spoerl

            @cwlmyjm
            Hi,
            Thanks for the analysis. What happens, if you play from the Mac directly, without Qt, and you select the USB device for output?

            C Offline
            C Offline
            cwlmyjm
            wrote on last edited by
            #5

            @Axel-Spoerl I cannot do that because I am writing a meeting program, and my program provides an insided audio output selection, change the selection in my pogram will not effect the system setting. There code are no issues running in Windows and Linux, but not work on mac.

            1 Reply Last reply
            0
            • Axel SpoerlA Axel Spoerl

              @cwlmyjm
              Hi,
              Thanks for the analysis. What happens, if you play from the Mac directly, without Qt, and you select the USB device for output?

              C Offline
              C Offline
              cwlmyjm
              wrote on last edited by
              #6

              @Axel-Spoerl Sorry for misunderstand your reply, When I select the USB device for output, with qt or without qt, it's no problem playing sound.

              Axel SpoerlA 1 Reply Last reply
              0
              • C cwlmyjm

                @Axel-Spoerl Sorry for misunderstand your reply, When I select the USB device for output, with qt or without qt, it's no problem playing sound.

                Axel SpoerlA Offline
                Axel SpoerlA Offline
                Axel Spoerl
                Moderators
                wrote on last edited by
                #7

                @cwlmyjm said in QAudioOutput::setDevice seems not work on mac:

                When I select the USB device for output, with qt or without qt, it's no problem playing sound.

                I don't understand: If there is no problem playing sound, if you select the USB device, with or without Qt - what is the problem?

                Software Engineer
                The Qt Company, Oslo

                C 1 Reply Last reply
                0
                • Axel SpoerlA Axel Spoerl

                  @cwlmyjm said in QAudioOutput::setDevice seems not work on mac:

                  When I select the USB device for output, with qt or without qt, it's no problem playing sound.

                  I don't understand: If there is no problem playing sound, if you select the USB device, with or without Qt - what is the problem?

                  C Offline
                  C Offline
                  cwlmyjm
                  wrote on last edited by
                  #8

                  @Axel-Spoerl What I want to achieve is: keep select the mac mini speaker in audio setting, my program has a build-in audio output menu and user can make selection in my program and the selection will only affect my program and not affect the system audio setting. To achieve this, I use QMediaDevices::audioOutputs to get all output device, then find the usb speaker, call setDevice to QAudioOutput and replay sound file, this works on window and Linux but not work on Mac. I mean the problem is calling setDevice not work, the sound still playing on Mac mini build-in speaker rather than my selection.

                  The quote "When I select the USB device for output, with qt or without qt, it's no problem playing sound." I mean my usb device has no problem, when I select usb device, the sound could play on it, but in this case, when I choose mac mini build-in speaker in my program, the sound still play on usb device. The problem is that QAudioOutput::setDevice not work, it does change the audio output device for QMediaPlayer.

                  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