volume control

This commit is contained in:
Anika Raemer 2021-10-13 13:01:19 +02:00
parent fe7bbed7c1
commit e9a031e6d3
7 changed files with 39 additions and 40 deletions

View file

@ -5,11 +5,14 @@
#include <QMediaPlayer>
#include <models/NavigationItemModel.h>
/**
* @brief MusicPlayer providing interface to QML and Navigation
*/
class MusicPlayer : public QMediaPlayer
{
Q_OBJECT
Q_PROPERTY(QObject* pCurrentItem READ getCurrentItem NOTIFY currentItemChanged)
Q_PROPERTY(QUrl pCoverImageSource READ getCoverImageSource NOTIFY coverImageSourceChanged)
Q_PROPERTY(bool pHasNext READ hasNext NOTIFY hasNextChanged)
Q_PROPERTY(bool pHasPrevious READ hasPrevious NOTIFY hasPreviousChanged)
Q_PROPERTY(bool pIsPlaying READ isPlaying NOTIFY isPlayingChanged)
@ -21,7 +24,7 @@ class MusicPlayer : public QMediaPlayer
signals:
void navigateTo(NavigationItemModel *item);
void currentItemChanged();
void coverImageSourceChanged();
void hasPreviousChanged();
void hasNextChanged();
void isPlayingChanged();
@ -32,23 +35,37 @@ signals:
public:
MusicPlayer(QObject *parent = Q_NULLPTR);
~MusicPlayer();
~MusicPlayer() =default;
void init(NavigationItemModel* item);
NavigationItemModel *getCurrentItem();
/**
* @brief Get path to media cover image.
* @return Path to media cover image.
*/
inline const QString& getCoverImageSource() const {return mCurrentItem->getImageSource();}
bool isPlaying() const;
bool hasNext() const;
bool hasPrevious() const;
inline int getAudioVolume() const { return mAudioVolume; }
/**
* @brief Set audio volume. Information is transferred to VlcAudio
* @brief Get audio volume. Range is in between 0 and 100
* Relays info from QMediaPlayer::volume as Q_PROPERTY does seem to have
* trouble accessing base class functions directly.
*/
inline int getAudioVolume() const { return volume(); }
/**
* @brief Set audio volume.
* @param newVolume value between 0 and 100 (audio level in percent)
* Ensures that volume is inbetween 0 and 100. If this range is exceeded,
* the volume is set to the lowest and highest allowed value, respectively.
*
* Relay info to QMediaPlayer::setVolume as Q_PROPERTY does seem to have
* trouble accessing base class functions directly.
*
* @todo save to config file?
*/
void setAudioVolume(int newVolume);
@ -81,7 +98,6 @@ private:
int mCurrentMediaItemLength = 0;
int mCurrentTime = 0;
double mCurrentMediaItemProgress = 0;
int mAudioVolume{50};
QString mMediaTitle = QString("");
NavigationItemModel* mCurrentItem = nullptr;
};