diff options
author | Piotr Srebrny <piotr.srebrny@qt.io> | 2021-09-17 16:44:04 +0200 |
---|---|---|
committer | Piotr Srebrny <piotr.srebrny@qt.io> | 2021-09-18 13:07:39 +0200 |
commit | 6b22d5f88d6a10835fb5e92f7302903918b1f508 (patch) | |
tree | cc69eeef290f982c47de74c93c40aeb43a1da6c2 /src/multimedia/audio/qaudiooutput.cpp | |
parent | 6b4792e63e0dfe6c568f0a79b426f004386ebe96 (diff) |
Reset audio device to default when setting null device
Interpret a null device as an invalid audio device. When setting
null device on QAudioInput/Output reset the device to default system
audio input/output.
Pick-to: 6.2
Change-Id: I22d75802ecfaa563b1cc55f03d68b5ca979f066a
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/multimedia/audio/qaudiooutput.cpp')
-rw-r--r-- | src/multimedia/audio/qaudiooutput.cpp | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/src/multimedia/audio/qaudiooutput.cpp b/src/multimedia/audio/qaudiooutput.cpp index 5f49e8f26..69cb7056f 100644 --- a/src/multimedia/audio/qaudiooutput.cpp +++ b/src/multimedia/audio/qaudiooutput.cpp @@ -85,13 +85,11 @@ \property QAudioOutput::device \brief The audio device connected to this output. - The device property represents the audio device connected to this output. - A default constructed - QAudioOutput object will be connected to the systems default audio output at - construction time. - - This property can be used to select any other output device listed by - QMediaDevices::audioOutputs(). + The device property represents the audio device this output is connected to. + This property can be used to select an output device from the + QMediaDevices::audioOutputs() list. + You can select the system default audio output by setting this property to + a default constructed QAudioDevice object. */ QAudioOutput::QAudioOutput(QObject *parent) @@ -102,9 +100,7 @@ QAudioOutput::QAudioOutput(const QAudioDevice &device, QObject *parent) : QObject(parent), d(QPlatformMediaIntegration::instance()->createAudioOutput(this)) { - d->device = device; - if (!d->device.isNull() && d->device.mode() != QAudioDevice::Output) - d->device = QMediaDevices::defaultAudioOutput(); + d->device = device.mode() == QAudioDevice::Output ? device : QMediaDevices::defaultAudioOutput(); d->setAudioDevice(d->device); } @@ -118,14 +114,23 @@ QAudioDevice QAudioOutput::device() const return d->device; } +/*! + Connects the audio output to the physical audio device described by + \a device. Using a default constructed QAudioDevice object as \a device + will connect the audio output to the system default audio output device. +*/ + void QAudioOutput::setDevice(const QAudioDevice &device) { - if (!device.isNull() && device.mode() != QAudioDevice::Output) + auto dev = device; + if (dev.isNull()) + dev = QMediaDevices::defaultAudioOutput(); + if (dev.mode() != QAudioDevice::Output) return; - if (d->device == device) + if (d->device == dev) return; - d->device = device; - d->setAudioDevice(device); + d->device = dev; + d->setAudioDevice(dev); emit deviceChanged(); } |