Add playbackrate capability to AudioManager

This commit is contained in:
Bart De Vries 2021-04-11 17:13:44 +02:00
parent 33f380e387
commit 6b62ba2cf9
2 changed files with 28 additions and 4 deletions

View File

@ -35,6 +35,7 @@ AudioManager::AudioManager(QObject *parent) : QObject(parent), d(std::make_uniqu
connect(&d->mPlayer, &QMediaPlayer::mediaStatusChanged, this, &AudioManager::mediaStatusChanged);
connect(&d->mPlayer, &QMediaPlayer::stateChanged, this, &AudioManager::playbackStateChanged);
connect(&d->mPlayer, &QMediaPlayer::stateChanged, this, &AudioManager::playerStateChanged);
connect(&d->mPlayer, &QMediaPlayer::playbackRateChanged, this, &AudioManager::playbackRateChanged);
connect(&d->mPlayer, QOverload<QMediaPlayer::Error>::of(&QMediaPlayer::error), this, &AudioManager::errorChanged);
connect(&d->mPlayer, &QMediaPlayer::durationChanged, this, &AudioManager::durationChanged);
connect(&d->mPlayer, &QMediaPlayer::positionChanged, this, &AudioManager::positionChanged);
@ -103,6 +104,11 @@ QMediaPlayer::State AudioManager::playbackState() const
return d->mPlayer.state();
}
qreal AudioManager::playbackRate() const
{
return d->mPlayer.playbackRate();
}
QMediaPlayer::MediaStatus AudioManager::status() const
{
return d->mPlayer.mediaStatus();
@ -111,13 +117,13 @@ QMediaPlayer::MediaStatus AudioManager::status() const
void AudioManager::setEntry(Entry* entry)
{
d->entry = entry;
Q_EMIT entryChanged();
Q_EMIT entryChanged(entry);
}
void AudioManager::setPlayerOpen(bool state)
{
d->playerOpen = state;
Q_EMIT playerOpenChanged();
Q_EMIT playerOpenChanged(state);
}
void AudioManager::setMuted(bool muted)
@ -140,6 +146,13 @@ void AudioManager::setSource(const QUrl &source)
d->mPlayer.setMedia({source});
}
void AudioManager::setPlaybackRate(const qreal rate)
{
qDebug() << "AudioManager::setPlaybackRate" << rate;
d->mPlayer.setPlaybackRate(rate);
}
void AudioManager::setPosition(qint64 position)
{
qDebug() << "AudioManager::setPosition" << position;

View File

@ -54,6 +54,11 @@ class AudioManager : public QObject
READ playbackState
NOTIFY playbackStateChanged)
Q_PROPERTY(qreal playbackRate
READ playbackRate
WRITE setPlaybackRate
NOTIFY playbackRateChanged)
Q_PROPERTY(QMediaPlayer::Error error
READ error
NOTIFY errorChanged)
@ -97,6 +102,8 @@ public:
[[nodiscard]] QMediaPlayer::State playbackState() const;
[[nodiscard]] qreal playbackRate() const;
[[nodiscard]] QMediaPlayer::Error error() const;
[[nodiscard]] qint64 duration() const;
@ -107,9 +114,9 @@ public:
Q_SIGNALS:
void playerOpenChanged();
void playerOpenChanged(bool state);
void entryChanged();
void entryChanged(Entry* entry);
void mutedChanged(bool muted);
@ -121,6 +128,8 @@ Q_SIGNALS:
void playbackStateChanged(QMediaPlayer::State state);
void playbackRateChanged(qreal rate);
void errorChanged(QMediaPlayer::Error error);
void durationChanged(qint64 duration);
@ -149,6 +158,8 @@ public Q_SLOTS:
void setPosition(qint64 position);
void setPlaybackRate(qreal rate);
void play();
void pause();