77 lines
2.1 KiB
C++
77 lines
2.1 KiB
C++
#ifndef MUSICPLAYER_H
|
|
#define MUSICPLAYER_H
|
|
|
|
#include <QObject>
|
|
#include <QMediaPlayer>
|
|
#include <models/NavigationItemModel.h>
|
|
|
|
/**
|
|
* @brief MusicPlayer providing interface to QML and Navigation
|
|
*/
|
|
class MusicPlayer : public QMediaPlayer
|
|
{
|
|
Q_OBJECT
|
|
|
|
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)
|
|
Q_PROPERTY(double pProgress READ getProgress NOTIFY progressChanged)
|
|
Q_PROPERTY(QString pMediaLength READ getMediaLength NOTIFY mediaLengthChanged)
|
|
Q_PROPERTY(QString pTime READ getTime NOTIFY progressChanged)
|
|
Q_PROPERTY(QString pMediaTitle READ getMediaTitle NOTIFY mediaTitleChanged)
|
|
|
|
signals:
|
|
void navigateTo(NavigationItemModel *item);
|
|
void coverImageSourceChanged();
|
|
void hasPreviousChanged();
|
|
void hasNextChanged();
|
|
void isPlayingChanged();
|
|
void progressChanged();
|
|
void mediaLengthChanged();
|
|
void mediaTitleChanged();
|
|
|
|
public:
|
|
MusicPlayer(QObject *parent = Q_NULLPTR);
|
|
~MusicPlayer() =default;
|
|
|
|
void init(NavigationItemModel* item);
|
|
|
|
/**
|
|
* @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;
|
|
|
|
double getProgress() const;
|
|
|
|
QString getMediaTitle() const;
|
|
QString getMediaLength();
|
|
QString getTime();
|
|
|
|
public slots:
|
|
void navigateBack();
|
|
void playPause();
|
|
void stopMusic();
|
|
void playNext();
|
|
void playPrevious();
|
|
|
|
private:
|
|
void reset();
|
|
void clearMediaList();
|
|
void readMedia(const QString& path);
|
|
QString timeToString(int time);
|
|
|
|
int mCurrentMediaItemLength = 0;
|
|
int mCurrentTime = 0;
|
|
double mCurrentMediaItemProgress = 0;
|
|
QString mMediaTitle = QString("");
|
|
NavigationItemModel* mCurrentItem = nullptr;
|
|
};
|
|
|
|
#endif // MUSICPLAYER_H
|