Refactor to use skipForward and skipBackward

This is done to make the distinction between skipping time and changing
track.
This commit is contained in:
Bart De Vries 2021-04-12 22:44:05 +02:00
parent 791c25ad19
commit 21feef8ce0
4 changed files with 25 additions and 21 deletions

View File

@ -125,12 +125,12 @@ bool AudioManager::canPause() const
return (d->m_readyToPlay); return (d->m_readyToPlay);
} }
bool AudioManager::canGoNext() const bool AudioManager::canSkipForward() const
{ {
return (d->m_readyToPlay); return (d->m_readyToPlay);
} }
bool AudioManager::canGoPrevious() const bool AudioManager::canSkipBackward() const
{ {
return (d->m_readyToPlay); return (d->m_readyToPlay);
} }
@ -207,14 +207,14 @@ void AudioManager::setEntry(Entry* entry)
Q_EMIT entryChanged(entry); Q_EMIT entryChanged(entry);
Q_EMIT canPlayChanged(); Q_EMIT canPlayChanged();
Q_EMIT canPauseChanged(); Q_EMIT canPauseChanged();
Q_EMIT canGoNextChanged(); Q_EMIT canSkipForwardChanged();
Q_EMIT canGoPreviousChanged(); Q_EMIT canSkipBackwardChanged();
} else { } else {
d->m_readyToPlay = false; d->m_readyToPlay = false;
Q_EMIT canPlayChanged(); Q_EMIT canPlayChanged();
Q_EMIT canPauseChanged(); Q_EMIT canPauseChanged();
Q_EMIT canGoNextChanged(); Q_EMIT canSkipForwardChanged();
Q_EMIT canGoPreviousChanged(); Q_EMIT canSkipBackwardChanged();
} }
} }
@ -296,15 +296,15 @@ void AudioManager::seek(qint64 position)
d->m_player.setPosition(position); d->m_player.setPosition(position);
} }
void AudioManager::next() void AudioManager::skipForward()
{ {
qDebug() << "AudioManager::next"; qDebug() << "AudioManager::skipForward";
seek(std::min((position() + SKIP_STEP), duration())); seek(std::min((position() + SKIP_STEP), duration()));
} }
void AudioManager::previous() void AudioManager::skipBackward()
{ {
qDebug() << "AudioManager::previous"; qDebug() << "AudioManager::skipBackward";
seek(std::max((qint64)0, (position() - SKIP_STEP))); seek(std::max((qint64)0, (position() - SKIP_STEP)));
} }

View File

@ -125,9 +125,9 @@ public:
[[nodiscard]] bool canPause() const; [[nodiscard]] bool canPause() const;
[[nodiscard]] bool canGoNext() const; [[nodiscard]] bool canSkipForward() const;
[[nodiscard]] bool canGoPrevious() const; [[nodiscard]] bool canSkipBackward() const;
Q_SIGNALS: Q_SIGNALS:
@ -165,9 +165,9 @@ Q_SIGNALS:
void canPauseChanged(); void canPauseChanged();
void canGoNextChanged(); void canSkipForwardChanged();
void canGoPreviousChanged(); void canSkipBackwardChanged();
public Q_SLOTS: public Q_SLOTS:
@ -195,9 +195,9 @@ public Q_SLOTS:
void seek(qint64 position); void seek(qint64 position);
void previous(); void skipBackward();
void next(); void skipForward();
private Q_SLOTS: private Q_SLOTS:

View File

@ -104,7 +104,7 @@ void MediaPlayer2Player::Next()
emit next(); emit next();
if (m_audioPlayer) { if (m_audioPlayer) {
m_audioPlayer->next(); m_audioPlayer->skipForward();
} }
} }
@ -116,7 +116,11 @@ bool MediaPlayer2Player::CanGoPrevious() const
void MediaPlayer2Player::Previous() void MediaPlayer2Player::Previous()
{ {
// not implemented emit previous();
if (m_audioPlayer) {
m_audioPlayer->skipBackward();
}
} }
bool MediaPlayer2Player::CanPause() const bool MediaPlayer2Player::CanPause() const

View File

@ -174,7 +174,7 @@ Kirigami.Page {
icon.width: parent.buttonsize icon.width: parent.buttonsize
flat: true flat: true
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
onClicked: audio.previous() onClicked: audio.skipBackward()
} }
Controls.Button { Controls.Button {
id: playButton id: playButton
@ -191,7 +191,7 @@ Kirigami.Page {
icon.width: parent.buttonsize icon.width: parent.buttonsize
flat: true flat: true
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
onClicked: audio.next() onClicked: audio.skipForward()
} }
Controls.Button { Controls.Button {
icon.name: "media-skip-forward" icon.name: "media-skip-forward"
@ -199,7 +199,7 @@ Kirigami.Page {
icon.width: parent.buttonsize icon.width: parent.buttonsize
flat: true flat: true
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
onClicked: audio.next() onClicked: console.log("Next track to be implemented")
} }
} }
} }