show media length and progress above progress bar
This commit is contained in:
parent
0b84a6e6b6
commit
470e95f57f
3 changed files with 63 additions and 19 deletions
|
|
@ -49,6 +49,13 @@ Item{
|
||||||
color: "#99ffffff"
|
color: "#99ffffff"
|
||||||
height: 140
|
height: 140
|
||||||
|
|
||||||
|
Label{
|
||||||
|
anchors.right: progress.right
|
||||||
|
anchors.bottom: progress.top
|
||||||
|
font.pointSize: 9
|
||||||
|
color: "grey"
|
||||||
|
text: musicModel.pTime + " / " + musicModel.pMediaLength
|
||||||
|
}
|
||||||
|
|
||||||
ProgressBar{
|
ProgressBar{
|
||||||
id: progress
|
id: progress
|
||||||
|
|
|
||||||
|
|
@ -23,10 +23,7 @@ void MusicModel::init(NavigationItemModel *item)
|
||||||
mCurrentItem = item;
|
mCurrentItem = item;
|
||||||
emit currentItemChanged();
|
emit currentItemChanged();
|
||||||
|
|
||||||
mHasNext = false;
|
reset();
|
||||||
mHasPrevious = false;
|
|
||||||
emit hasNextChanged();
|
|
||||||
emit hasPrevious();
|
|
||||||
|
|
||||||
while(mMedia->count() > 0){
|
while(mMedia->count() > 0){
|
||||||
mMedia->removeMedia(0);
|
mMedia->removeMedia(0);
|
||||||
|
|
@ -64,13 +61,7 @@ void MusicModel::stopMusic()
|
||||||
mIsPlaying = false;
|
mIsPlaying = false;
|
||||||
emit isPlayingChanged();
|
emit isPlayingChanged();
|
||||||
|
|
||||||
mHasNext = false;
|
reset();
|
||||||
mHasPrevious = false;
|
|
||||||
emit hasNextChanged();
|
|
||||||
emit hasPreviousChanged();
|
|
||||||
|
|
||||||
mCurrentMediaItemProgress = 0.0;
|
|
||||||
emit progressChanged();
|
|
||||||
|
|
||||||
emit stop();
|
emit stop();
|
||||||
}
|
}
|
||||||
|
|
@ -104,26 +95,36 @@ VlcMediaList *MusicModel::getMedia()
|
||||||
return mMedia;
|
return mMedia;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MusicModel::isPlaying()
|
bool MusicModel::isPlaying() const
|
||||||
{
|
{
|
||||||
return mIsPlaying;
|
return mIsPlaying;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MusicModel::hasNext()
|
bool MusicModel::hasNext() const
|
||||||
{
|
{
|
||||||
return mHasNext;
|
return mHasNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MusicModel::hasPrevious()
|
bool MusicModel::hasPrevious() const
|
||||||
{
|
{
|
||||||
return mHasPrevious;
|
return mHasPrevious;
|
||||||
}
|
}
|
||||||
|
|
||||||
double MusicModel::getProgress()
|
double MusicModel::getProgress() const
|
||||||
{
|
{
|
||||||
return mCurrentMediaItemProgress;
|
return mCurrentMediaItemProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString MusicModel::getMediaLength()
|
||||||
|
{
|
||||||
|
return timeToString(mCurrentMediaItemLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString MusicModel::getTime()
|
||||||
|
{
|
||||||
|
return timeToString(mCurrentTime);
|
||||||
|
}
|
||||||
|
|
||||||
void MusicModel::onNextMediaSet(VlcMedia *media)
|
void MusicModel::onNextMediaSet(VlcMedia *media)
|
||||||
{
|
{
|
||||||
mHasNext = true;
|
mHasNext = true;
|
||||||
|
|
@ -141,10 +142,36 @@ void MusicModel::onNextMediaSet(VlcMedia *media)
|
||||||
void MusicModel::onTimeChanged(int time)
|
void MusicModel::onTimeChanged(int time)
|
||||||
{
|
{
|
||||||
mCurrentMediaItemProgress = (double) time / mCurrentMediaItemLength;
|
mCurrentMediaItemProgress = (double) time / mCurrentMediaItemLength;
|
||||||
|
mCurrentTime = time;
|
||||||
emit progressChanged();
|
emit progressChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MusicModel::onLengthChanged(int length)
|
void MusicModel::onLengthChanged(int length)
|
||||||
{
|
{
|
||||||
mCurrentMediaItemLength= length;
|
mCurrentMediaItemLength= length;
|
||||||
|
emit mediaLengthChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MusicModel::reset()
|
||||||
|
{
|
||||||
|
mHasNext = false;
|
||||||
|
mHasPrevious = false;
|
||||||
|
emit hasNextChanged();
|
||||||
|
emit hasPreviousChanged();
|
||||||
|
|
||||||
|
mCurrentMediaItemProgress = 0.0;
|
||||||
|
mCurrentTime = 0.0;
|
||||||
|
emit progressChanged();
|
||||||
|
|
||||||
|
mCurrentMediaItemLength = 0.0;
|
||||||
|
emit mediaLengthChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString MusicModel::timeToString(int time)
|
||||||
|
{
|
||||||
|
int sec = time/1000;
|
||||||
|
int min = sec/60;
|
||||||
|
sec = sec-min*60;
|
||||||
|
QString secStr = sec < 10 ? "0"+QString::number(sec) : QString::number(sec);
|
||||||
|
return QString::number(min) + ":" + secStr;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ class MusicModel : public QObject
|
||||||
Q_PROPERTY(bool pHasPrevious READ hasPrevious NOTIFY hasPreviousChanged)
|
Q_PROPERTY(bool pHasPrevious READ hasPrevious NOTIFY hasPreviousChanged)
|
||||||
Q_PROPERTY(bool pIsPlaying READ isPlaying NOTIFY isPlayingChanged)
|
Q_PROPERTY(bool pIsPlaying READ isPlaying NOTIFY isPlayingChanged)
|
||||||
Q_PROPERTY(double pProgress READ getProgress NOTIFY progressChanged)
|
Q_PROPERTY(double pProgress READ getProgress NOTIFY progressChanged)
|
||||||
|
Q_PROPERTY(QString pMediaLength READ getMediaLength NOTIFY mediaLengthChanged)
|
||||||
|
Q_PROPERTY(QString pTime READ getTime NOTIFY progressChanged)
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void navigateTo(NavigationItemModel *item);
|
void navigateTo(NavigationItemModel *item);
|
||||||
|
|
@ -28,6 +30,7 @@ signals:
|
||||||
void hasNextChanged();
|
void hasNextChanged();
|
||||||
void isPlayingChanged();
|
void isPlayingChanged();
|
||||||
void progressChanged();
|
void progressChanged();
|
||||||
|
void mediaLengthChanged();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MusicModel(VlcInstance* instance, QObject *parent = Q_NULLPTR);
|
MusicModel(VlcInstance* instance, QObject *parent = Q_NULLPTR);
|
||||||
|
|
@ -45,11 +48,14 @@ public:
|
||||||
|
|
||||||
VlcMediaList *getMedia();
|
VlcMediaList *getMedia();
|
||||||
|
|
||||||
bool isPlaying();
|
bool isPlaying() const;
|
||||||
bool hasNext();
|
bool hasNext() const;
|
||||||
bool hasPrevious();
|
bool hasPrevious() const;
|
||||||
|
|
||||||
double getProgress();
|
double getProgress() const;
|
||||||
|
|
||||||
|
QString getMediaLength();
|
||||||
|
QString getTime();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onNextMediaSet(VlcMedia* media);
|
void onNextMediaSet(VlcMedia* media);
|
||||||
|
|
@ -57,10 +63,14 @@ public slots:
|
||||||
void onLengthChanged(int length);
|
void onLengthChanged(int length);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void reset();
|
||||||
|
QString timeToString(int time);
|
||||||
|
|
||||||
bool mIsPlaying = false;
|
bool mIsPlaying = false;
|
||||||
bool mHasNext = false;
|
bool mHasNext = false;
|
||||||
bool mHasPrevious = false;
|
bool mHasPrevious = false;
|
||||||
int mCurrentMediaItemLength = 0;
|
int mCurrentMediaItemLength = 0;
|
||||||
|
int mCurrentTime = 0;
|
||||||
double mCurrentMediaItemProgress = 0;
|
double mCurrentMediaItemProgress = 0;
|
||||||
NavigationItemModel* mCurrentItem = Q_NULLPTR;
|
NavigationItemModel* mCurrentItem = Q_NULLPTR;
|
||||||
VlcMediaList* mMedia = Q_NULLPTR;
|
VlcMediaList* mMedia = Q_NULLPTR;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue