fix previous button, single point of definition
This commit is contained in:
parent
a483a380d6
commit
75308b4423
4 changed files with 100 additions and 34 deletions
|
|
@ -6,7 +6,10 @@
|
|||
#include <models/NavigationItemModel.h>
|
||||
|
||||
/**
|
||||
* @brief MusicPlayer providing interface to QML and Navigation
|
||||
* @brief MusicPlayer providing interface to QML and Navigation.
|
||||
*
|
||||
* Adds media from directory referenced by the current navigation item to
|
||||
* playlist and provides interface to QML MusicPlayer.
|
||||
*/
|
||||
class MusicPlayer : public QMediaPlayer
|
||||
{
|
||||
|
|
@ -17,9 +20,9 @@ class MusicPlayer : public QMediaPlayer
|
|||
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)
|
||||
Q_PROPERTY(QString pMediaLength READ getMediaDuration NOTIFY mediaLengthChanged)
|
||||
Q_PROPERTY(QString pTime READ getPosition NOTIFY progressChanged)
|
||||
Q_PROPERTY(QString pMediaTitle READ getMediaTitle NOTIFY metaDataChanged)
|
||||
|
||||
signals:
|
||||
void navigateTo(NavigationItemModel *item);
|
||||
|
|
@ -29,12 +32,16 @@ signals:
|
|||
void isPlayingChanged();
|
||||
void progressChanged();
|
||||
void mediaLengthChanged();
|
||||
void mediaTitleChanged();
|
||||
|
||||
public:
|
||||
MusicPlayer(QObject *parent = Q_NULLPTR);
|
||||
~MusicPlayer() =default;
|
||||
|
||||
/**
|
||||
* @brief Init playlist with media from directory referenced by item.
|
||||
* @param item Navigation item representing a leaf
|
||||
* @see void readMedia(const QString& path)
|
||||
*/
|
||||
void init(NavigationItemModel* item);
|
||||
|
||||
/**
|
||||
|
|
@ -42,23 +49,71 @@ public:
|
|||
* @return Path to media cover image.
|
||||
*/
|
||||
inline const QString& getCoverImageSource() const {return mCurrentItem->getImageSource();}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Indicates whether the media player is currently playing a track.
|
||||
* @return true if media player is playing a track.
|
||||
*/
|
||||
bool isPlaying() const;
|
||||
/**
|
||||
* @brief Indicates whether there is a next item in the playlist.
|
||||
* @return True if there is a next item in the playlist
|
||||
* Does not wrap.
|
||||
*/
|
||||
bool hasNext() const;
|
||||
/**
|
||||
* @brief Indicates whether there is a previous item in the playlist.
|
||||
* @return True if there is a previous item in the playlist
|
||||
* Does not wrap.
|
||||
*/
|
||||
bool hasPrevious() const;
|
||||
|
||||
/**
|
||||
* @brief Get media progress as value in between 0 and 1
|
||||
* @return Media progress
|
||||
* 0 corresponds to the beginning and 1 to the end of the current track.
|
||||
*/
|
||||
double getProgress() const;
|
||||
|
||||
/**
|
||||
* @brief Get current media title extracted from media meta data (id3 tags)
|
||||
* @return Current media title
|
||||
*/
|
||||
QString getMediaTitle() const;
|
||||
QString getMediaLength();
|
||||
QString getTime();
|
||||
/**
|
||||
* @brief Get duration of the current track
|
||||
* @return Duration of the current track formatted as string
|
||||
* @see QMediaPlayer::duration()
|
||||
* @see millisecondsToString(int timeInMilliseconds) const
|
||||
*/
|
||||
QString getMediaDuration() const;
|
||||
/**
|
||||
* @brief Get current position within the track
|
||||
* @return Postion within the track formatted as string
|
||||
* @see QMediaPlayer::position()
|
||||
* @see millisecondsToString(int timeInMilliseconds) const
|
||||
*/
|
||||
QString getPosition() const;
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* @brief Navigate back to navgation list
|
||||
*/
|
||||
void navigateBack();
|
||||
/**
|
||||
* @brief Play or pause music depending on whether it is currently playing
|
||||
*/
|
||||
void playPause();
|
||||
/**
|
||||
* @brief Stop music and reset track to first track in playlist
|
||||
*/
|
||||
void stopMusic();
|
||||
/**
|
||||
* @brief Play next track in current playlist if available
|
||||
*/
|
||||
void playNext();
|
||||
/**
|
||||
* @brief Replay previoustrack in current playlist if available
|
||||
*/
|
||||
void playPrevious();
|
||||
|
||||
private:
|
||||
|
|
@ -66,20 +121,22 @@ private:
|
|||
* @brief Resets playlist to first track if playlist exists and is non-empty
|
||||
*/
|
||||
void resetPlaylistToFirstTrack();
|
||||
/**
|
||||
* @brief Clear the current playlist
|
||||
*/
|
||||
void clearPlaylist();
|
||||
/**
|
||||
* @brief Add all media from path to playlist
|
||||
* @param path Path to media
|
||||
*/
|
||||
void readMedia(const QString& path);
|
||||
/**
|
||||
* @brief Transforms time in milliseconds into a string
|
||||
* @brief Format time in milliseconds acoording to [M]m:ss
|
||||
* @param time Time in ms
|
||||
* @return
|
||||
* @todo use QDateTime
|
||||
* @return formateted string
|
||||
*/
|
||||
QString timeToString(int time);
|
||||
QString millisecondsToString(int timeInMilliseconds) const;
|
||||
|
||||
int mCurrentMediaItemLength = 0;
|
||||
int mCurrentTime = 0;
|
||||
double mCurrentMediaItemProgress = 0;
|
||||
QString mMediaTitle = QString("");
|
||||
NavigationItemModel* mCurrentItem = nullptr;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue