volume control
This commit is contained in:
parent
fe7bbed7c1
commit
e9a031e6d3
7 changed files with 39 additions and 40 deletions
|
|
@ -6,11 +6,10 @@
|
|||
|
||||
MusicPlayer::MusicPlayer(QObject *parent) : QMediaPlayer(parent)
|
||||
{
|
||||
/* nothing */
|
||||
}
|
||||
|
||||
MusicPlayer::~MusicPlayer()
|
||||
{
|
||||
// relay base class signal as NOTIFY doesn't seem to be able to handle it directly
|
||||
connect(this, &QMediaPlayer::volumeChanged, this, &MusicPlayer::audioVolumeChanged);
|
||||
// init audio
|
||||
setAudioVolume(50);
|
||||
}
|
||||
|
||||
void MusicPlayer::init(NavigationItemModel *item)
|
||||
|
|
@ -19,7 +18,7 @@ void MusicPlayer::init(NavigationItemModel *item)
|
|||
return;
|
||||
}
|
||||
mCurrentItem = item;
|
||||
emit currentItemChanged();
|
||||
emit coverImageSourceChanged();
|
||||
|
||||
reset();
|
||||
clearMediaList();
|
||||
|
|
@ -72,11 +71,6 @@ void MusicPlayer::playPrevious()
|
|||
}
|
||||
}
|
||||
|
||||
NavigationItemModel *MusicPlayer::getCurrentItem()
|
||||
{
|
||||
return mCurrentItem;
|
||||
}
|
||||
|
||||
bool MusicPlayer::isPlaying() const
|
||||
{
|
||||
return mIsPlaying;
|
||||
|
|
@ -94,15 +88,10 @@ bool MusicPlayer::hasPrevious() const
|
|||
|
||||
void MusicPlayer::setAudioVolume(int newVolume)
|
||||
{
|
||||
if(newVolume != mAudioVolume){
|
||||
if(newVolume > 100){
|
||||
mAudioVolume = 100;
|
||||
} else if(newVolume < 0){
|
||||
mAudioVolume = 0;
|
||||
} else {
|
||||
mAudioVolume = newVolume;
|
||||
}
|
||||
emit audioVolumeChanged(mAudioVolume);
|
||||
if(newVolume != volume()){
|
||||
qDebug() << volume() << newVolume;
|
||||
setVolume(newVolume);
|
||||
// signal audioVolumeChanged will be emitted automatically
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue