The QAudioDeviceInfo class provides an interface to query audio devices and their functionality. More...
Header: | #include <QAudioDeviceInfo> |
qmake: | QT += multimedia |
QAudioDeviceInfo() | |
QAudioDeviceInfo(const QAudioDeviceInfo &other) | |
~QAudioDeviceInfo() | |
QString | deviceName() const |
bool | isFormatSupported(const QAudioFormat &settings) const |
bool | isNull() const |
QAudioFormat | nearestFormat(const QAudioFormat &settings) const |
QAudioFormat | preferredFormat() const |
QList<QAudioFormat::Endian> | supportedByteOrders() const |
QList<int> | supportedChannelCounts() const |
QStringList | supportedCodecs() const |
QList<int> | supportedSampleRates() const |
QList<int> | supportedSampleSizes() const |
QList<QAudioFormat::SampleType> | supportedSampleTypes() const |
bool | operator!=(const QAudioDeviceInfo &other) const |
QAudioDeviceInfo & | operator=(const QAudioDeviceInfo &other) |
bool | operator==(const QAudioDeviceInfo &other) const |
QList<QAudioDeviceInfo> | availableDevices(QAudio::Mode mode) |
QAudioDeviceInfo | defaultInputDevice() |
QAudioDeviceInfo | defaultOutputDevice() |
The QAudioDeviceInfo class provides an interface to query audio devices and their functionality.
QAudioDeviceInfo lets you query for audio devices--such as sound cards and USB headsets--that are currently available on the system. The audio devices available are dependent on the platform or audio plugins installed.
A QAudioDeviceInfo is used by Qt to construct classes that communicate with the device--such as QAudioInput, and QAudioOutput.
You can also query each device for the formats it supports. A format in this context is a set consisting of a specific byte order, channel, codec, frequency, sample rate, and sample type. A format is represented by the QAudioFormat class.
The values supported by the device for each of these parameters can be fetched with supportedByteOrders(), supportedChannelCounts(), supportedCodecs(), supportedSampleRates(), supportedSampleSizes(), and supportedSampleTypes(). The combinations supported are dependent on the platform, audio plugins installed and the audio device capabilities. If you need a specific format, you can check if the device supports it with isFormatSupported(), or fetch a supported format that is as close as possible to the format with nearestFormat(). For instance:
QAudioFormat format; format.setSampleRate(44100); // ... other format parameters format.setSampleType(QAudioFormat::SignedInt); QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice()); if (!info.isFormatSupported(format)) format = info.nearestFormat(format);
The static functions defaultInputDevice(), defaultOutputDevice(), and availableDevices() let you get a list of all available devices. Devices are fetched according to the value of mode this is specified by the QAudio::Mode enum. The QAudioDeviceInfo returned are only valid for the QAudio::Mode.
For instance:
foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(QAudio::AudioOutput)) qDebug() << "Device name: " << deviceInfo.deviceName();
In this code sample, we loop through all devices that are able to output sound, i.e., play an audio stream in a supported format. For each device we find, we simply print the deviceName().
See also QAudioOutput and QAudioInput.
Constructs an empty QAudioDeviceInfo object.
Constructs a copy of other.
Destroy this audio device info.
[static]
QList<QAudioDeviceInfo> QAudioDeviceInfo::availableDevices(QAudio::Mode mode)Returns a list of audio devices that support mode.
[static]
QAudioDeviceInfo
QAudioDeviceInfo::defaultInputDevice()Returns the information for the default input audio device. All platform and audio plugin implementations provide a default audio device to use.
[static]
QAudioDeviceInfo
QAudioDeviceInfo::defaultOutputDevice()Returns the information for the default output audio device. All platform and audio plugin implementations provide a default audio device to use.
Returns the human readable name of the audio device.
Device names vary depending on the platform/audio plugin being used.
They are a unique string identifier for the audio device.
eg. default, Intel, U0x46d0x9a4
Returns true if the supplied settings are supported by the audio device described by this QAudioDeviceInfo.
Returns whether this QAudioDeviceInfo object holds a valid device definition.
Returns the closest QAudioFormat to the supplied settings that the system supports.
These settings are provided by the platform/audio plugin being used.
They are also dependent on the QAudio::Mode being used.
Returns the default audio format settings for this device.
These settings are provided by the platform/audio plugin being used.
They are also dependent on the QAudio::Mode being used.
A typical audio system would provide something like:
Returns a list of supported byte orders.
Returns a list of supported channel counts.
This is typically 1 for mono sound, or 2 for stereo sound.
Returns a list of supported codecs.
All platform and plugin implementations should provide support for:
"audio/pcm" - Linear PCM
For writing plugins to support additional codecs refer to:
http://www.iana.org/assignments/media-types/audio/
Returns a list of supported sample rates (in Hertz).
Returns a list of supported sample sizes (in bits).
Typically this will include 8 and 16 bit sample sizes.
Returns a list of supported sample types.
Returns true if this QAudioDeviceInfo class represents a different audio device than other
Sets the QAudioDeviceInfo object to be equal to other.
Returns true if this QAudioDeviceInfo class represents the same audio device as other.