QAudioOutput::setDevice seems not work on mac
-
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
-
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
@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 addqDebug() << devices;
above the for loop.
Cheers Axel -
@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 addqDebug() << devices;
above the for loop.
Cheers Axel@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.
and the following is my audio setting
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-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.
and the following is my audio setting
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.
@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? -
@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?@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.
-
@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?@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-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.
@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?
-
@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?
@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.