summaryrefslogtreecommitdiffstats
path: root/src/multimedia/audio/qaudiooutput.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2021-06-07 12:21:09 +0200
committerLars Knoll <lars.knoll@qt.io>2021-06-11 15:12:36 +0200
commitfc9cc90818a56b919ea1e50838bd13376b268bfe (patch)
treea18fb6dddd5e873d1e9fdf2bb944132070833a42 /src/multimedia/audio/qaudiooutput.cpp
parent923a000261717ba6c898205bc4a5973b34bed2c5 (diff)
Use QAudioOutput in QMediaPlayer
Adjust QMediaPlayer to the new audio output architecture. One now needs to explicitly add a QAudioOutput to the media player to get audio playback. While this requires two more lines of code to set up the media player, it does make the API consistent between audio and video and also consistent with what we have in QMediaCaptureSession. Adjusted auto tests where required and ported all platforms. Change-Id: I247e915e4862dee6d6bce367b83664b1d1d69726 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/multimedia/audio/qaudiooutput.cpp')
-rw-r--r--src/multimedia/audio/qaudiooutput.cpp42
1 files changed, 41 insertions, 1 deletions
diff --git a/src/multimedia/audio/qaudiooutput.cpp b/src/multimedia/audio/qaudiooutput.cpp
index c2590533b..c29251533 100644
--- a/src/multimedia/audio/qaudiooutput.cpp
+++ b/src/multimedia/audio/qaudiooutput.cpp
@@ -49,6 +49,7 @@
\inmodule QtMultimedia
\ingroup multimedia
\ingroup multimedia_audio
+ \since 6.0
QAudioOutput represents an output channel that can be used together with QMediaPlayer or
QMediaCaptureSession. It allows selecting the physical output device to be used, muting the channel
@@ -86,6 +87,16 @@
This property can be used to select any other output device listed by QMediaDevices::audioOutputs().
*/
+/*!
+ \property QAudioOutput::audioRole
+ \brief the role of the audio played by this output.
+
+ It can be set to specify the type of audio being played, allowing the system to make
+ appropriate decisions when it comes to volume, routing or post-processing.
+
+ \sa supportedAudioRoles()
+*/
+
QAudioOutput::QAudioOutput(QObject *parent)
: QAudioOutput(QMediaDevices::defaultAudioOutput(), parent)
{}
@@ -112,7 +123,7 @@ QAudioDevice QAudioOutput::device() const
void QAudioOutput::setDevice(const QAudioDevice &device)
{
- if (device.mode() != QAudio::AudioOutput)
+ if (!device.isNull() && device.mode() != QAudio::AudioOutput)
return;
if (d->device == device)
return;
@@ -128,6 +139,7 @@ float QAudioOutput::volume() const
void QAudioOutput::setVolume(float volume)
{
+ volume = qBound(0., volume, 1.);
if (d->volume == volume)
return;
d->volume = volume;
@@ -140,6 +152,23 @@ bool QAudioOutput::isMuted() const
return d->muted;
}
+QAudio::Role QAudioOutput::audioRole() const
+{
+ return d->role;
+}
+
+/*!
+ Returns a list of supported audio roles.
+
+ If setting the audio role is not supported, an empty list is returned.
+
+ \sa audioRole
+*/
+QList<QAudio::Role> QAudioOutput::supportedAudioRoles() const
+{
+ return d->supportedAudioRoles();
+}
+
void QAudioOutput::setMuted(bool muted)
{
if (d->muted == muted)
@@ -149,4 +178,15 @@ void QAudioOutput::setMuted(bool muted)
emit mutedChanged(muted);
}
+void QAudioOutput::setAudioRole(QAudio::Role audioRole)
+{
+ if (d->role == audioRole)
+ return;
+ if (!d->supportedAudioRoles().contains(audioRole))
+ return;
+ d->role = audioRole;
+ d->setAudioRole(d->role);
+ emit audioRoleChanged(d->role);
+}
+
#include "moc_qaudiooutput.cpp"