diff options
Diffstat (limited to 'src/multimedia/playback')
-rw-r--r-- | src/multimedia/playback/qmediaplayer.cpp | 90 | ||||
-rw-r--r-- | src/multimedia/playback/qmediaplayer.h | 7 |
2 files changed, 95 insertions, 2 deletions
diff --git a/src/multimedia/playback/qmediaplayer.cpp b/src/multimedia/playback/qmediaplayer.cpp index 16fdec8ea..e1fa31451 100644 --- a/src/multimedia/playback/qmediaplayer.cpp +++ b/src/multimedia/playback/qmediaplayer.cpp @@ -49,6 +49,7 @@ #include <qmediaplaylistsourcecontrol_p.h> #include <qmedianetworkaccesscontrol.h> #include <qaudiorolecontrol.h> +#include <qcustomaudiorolecontrol.h> #include <QtCore/qcoreevent.h> #include <QtCore/qmetaobject.h> @@ -111,6 +112,7 @@ public: : provider(0) , control(0) , audioRoleControl(0) + , customAudioRoleControl(0) , playlist(0) , networkAccessControl(0) , state(QMediaPlayer::StoppedState) @@ -124,6 +126,7 @@ public: QMediaServiceProvider *provider; QMediaPlayerControl* control; QAudioRoleControl *audioRoleControl; + QCustomAudioRoleControl *customAudioRoleControl; QString errorString; QPointer<QObject> videoOutput; @@ -616,6 +619,15 @@ QMediaPlayer::QMediaPlayer(QObject *parent, QMediaPlayer::Flags flags): if (d->audioRoleControl) { connect(d->audioRoleControl, &QAudioRoleControl::audioRoleChanged, this, &QMediaPlayer::audioRoleChanged); + + d->customAudioRoleControl = qobject_cast<QCustomAudioRoleControl *>( + d->service->requestControl(QCustomAudioRoleControl_iid)); + if (d->customAudioRoleControl) { + connect(d->customAudioRoleControl, + &QCustomAudioRoleControl::customAudioRoleChanged, + this, + &QMediaPlayer::customAudioRoleChanged); + } } } if (d->networkAccessControl != 0) { @@ -641,6 +653,8 @@ QMediaPlayer::~QMediaPlayer() d->service->releaseControl(d->control); if (d->audioRoleControl) d->service->releaseControl(d->audioRoleControl); + if (d->customAudioRoleControl) + d->service->releaseControl(d->customAudioRoleControl); d->provider->releaseService(d->service); } @@ -1150,8 +1164,13 @@ void QMediaPlayer::setAudioRole(QAudio::Role audioRole) { Q_D(QMediaPlayer); - if (d->audioRoleControl) + if (d->audioRoleControl) { + if (d->customAudioRoleControl != nullptr && d->audioRoleControl->audioRole() != audioRole) { + d->customAudioRoleControl->setCustomAudioRole(QString()); + } + d->audioRoleControl->setAudioRole(audioRole); + } } /*! @@ -1172,6 +1191,48 @@ QList<QAudio::Role> QMediaPlayer::supportedAudioRoles() const return QList<QAudio::Role>(); } +QString QMediaPlayer::customAudioRole() const +{ + Q_D(const QMediaPlayer); + + if (audioRole() != QAudio::CustomRole) + return QString(); + + if (d->customAudioRoleControl != nullptr) + return d->customAudioRoleControl->customAudioRole(); + + return QString(); +} + +void QMediaPlayer::setCustomAudioRole(const QString &audioRole) +{ + Q_D(QMediaPlayer); + + if (d->customAudioRoleControl) { + Q_ASSERT(d->audioRoleControl); + setAudioRole(QAudio::CustomRole); + d->customAudioRoleControl->setCustomAudioRole(audioRole); + } +} + +/*! + Returns a list of supported custom audio roles. An empty list may + indicate that the supported custom audio roles aren't known. The + list may not be complete. + + \since 5.10 + \sa customAudioRole +*/ +QStringList QMediaPlayer::supportedCustomAudioRoles() const +{ + Q_D(const QMediaPlayer); + + if (d->customAudioRoleControl) + return d->customAudioRoleControl->supportedCustomAudioRoles(); + + return QStringList(); +} + // Enums /*! \enum QMediaPlayer::State @@ -1279,6 +1340,14 @@ QList<QAudio::Role> QMediaPlayer::supportedAudioRoles() const \since 5.6 */ +/*! + \fn void QMediaPlayer::customAudioRoleChanged(const QString &role) + + Signals that the audio \a role of the media player has changed. + + \since 5.10 +*/ + // Properties /*! \property QMediaPlayer::state @@ -1461,11 +1530,30 @@ QList<QAudio::Role> QMediaPlayer::supportedAudioRoles() const The audio role must be set before calling setMedia(). + customAudioRole is cleared when this property is set to anything other than + QAudio::CustomRole. + \since 5.6 \sa supportedAudioRoles() */ /*! + \property QMediaPlayer::customAudioRole + \brief the role of the audio stream played by the media player. + + It can be set to specify the type of audio being played when the backend supports + audio roles unknown to Qt. Specifying a role allows the system to make appropriate + decisions when it comes to volume, routing or post-processing. + + The audio role must be set before calling setMedia(). + + audioRole is set to QAudio::CustomRole when this property is set. + + \since 5.10 + \sa supportedCustomAudioRoles() +*/ + +/*! \fn void QMediaPlayer::durationChanged(qint64 duration) Signal the duration of the content has changed to \a duration, expressed in milliseconds. diff --git a/src/multimedia/playback/qmediaplayer.h b/src/multimedia/playback/qmediaplayer.h index f23a94104..4e676a2d8 100644 --- a/src/multimedia/playback/qmediaplayer.h +++ b/src/multimedia/playback/qmediaplayer.h @@ -73,7 +73,8 @@ class Q_MULTIMEDIA_EXPORT QMediaPlayer : public QMediaObject Q_PROPERTY(qreal playbackRate READ playbackRate WRITE setPlaybackRate NOTIFY playbackRateChanged) Q_PROPERTY(State state READ state NOTIFY stateChanged) Q_PROPERTY(MediaStatus mediaStatus READ mediaStatus NOTIFY mediaStatusChanged) - Q_PROPERTY(QAudio::Role audioRole READ audioRole WRITE setAudioRole) + Q_PROPERTY(QAudio::Role audioRole READ audioRole WRITE setAudioRole NOTIFY audioRoleChanged) + Q_PROPERTY(QString customAudioRole READ customAudioRole WRITE setCustomAudioRole NOTIFY customAudioRoleChanged) Q_PROPERTY(QString error READ errorString) Q_ENUMS(State) Q_ENUMS(MediaStatus) @@ -162,6 +163,9 @@ public: QAudio::Role audioRole() const; void setAudioRole(QAudio::Role audioRole); QList<QAudio::Role> supportedAudioRoles() const; + QString customAudioRole() const; + void setCustomAudioRole(const QString &audioRole); + QStringList supportedCustomAudioRoles() const; public Q_SLOTS: void play(); @@ -200,6 +204,7 @@ Q_SIGNALS: void playbackRateChanged(qreal rate); void audioRoleChanged(QAudio::Role role); + void customAudioRoleChanged(const QString &role); void error(QMediaPlayer::Error error); |