fixed progress
This commit is contained in:
parent
2d985ca17d
commit
39a0356a51
2 changed files with 14 additions and 32 deletions
|
|
@ -16,6 +16,13 @@ MusicPlayer::MusicPlayer(QObject *parent) : QMediaPlayer(parent)
|
|||
emit hasNextChanged();
|
||||
emit hasPreviousChanged();
|
||||
});
|
||||
connect(this, &QMediaPlayer::positionChanged, this, [this](qint64){
|
||||
emit progressChanged();
|
||||
});
|
||||
connect(this, &QMediaPlayer::durationChanged, this, [this](qint64){
|
||||
emit progressChanged();
|
||||
emit mediaLengthChanged();
|
||||
});
|
||||
}
|
||||
|
||||
void MusicPlayer::init(NavigationItemModel *item)
|
||||
|
|
@ -26,7 +33,6 @@ void MusicPlayer::init(NavigationItemModel *item)
|
|||
mCurrentItem = item;
|
||||
emit coverImageSourceChanged();
|
||||
|
||||
reset();
|
||||
clearMediaList();
|
||||
|
||||
readMedia(mCurrentItem->getPath());
|
||||
|
|
@ -48,7 +54,6 @@ void MusicPlayer::playPause()
|
|||
void MusicPlayer::stopMusic()
|
||||
{
|
||||
if(isPlaying()){
|
||||
reset();
|
||||
stop();
|
||||
}
|
||||
}
|
||||
|
|
@ -86,12 +91,15 @@ bool MusicPlayer::hasPrevious() const
|
|||
/* player inits with currentIndex -1 and hence previousIndex = last index
|
||||
* until started. Yet, previousButton should initially be disabled.
|
||||
*/
|
||||
return previousIndex >= 0 && previousIndex < playlist()->currentIndex();
|
||||
return previousIndex >= 0 && previousIndex >= playlist()->currentIndex();
|
||||
}
|
||||
|
||||
double MusicPlayer::getProgress() const
|
||||
{
|
||||
return mCurrentMediaItemProgress;
|
||||
if(duration() <= 0 || position() < 0){
|
||||
return 0.0;
|
||||
}
|
||||
return (double)position()/duration();
|
||||
}
|
||||
|
||||
QString MusicPlayer::getMediaTitle() const
|
||||
|
|
@ -101,35 +109,12 @@ QString MusicPlayer::getMediaTitle() const
|
|||
|
||||
QString MusicPlayer::getMediaLength()
|
||||
{
|
||||
return timeToString(mCurrentMediaItemLength);
|
||||
return timeToString(duration());
|
||||
}
|
||||
|
||||
QString MusicPlayer::getTime()
|
||||
{
|
||||
return timeToString(mCurrentTime);
|
||||
}
|
||||
|
||||
void MusicPlayer::onTimeChanged(int time)
|
||||
{
|
||||
mCurrentMediaItemProgress = (double) time / mCurrentMediaItemLength;
|
||||
mCurrentTime = time;
|
||||
emit progressChanged();
|
||||
}
|
||||
|
||||
void MusicPlayer::onLengthChanged(int length)
|
||||
{
|
||||
mCurrentMediaItemLength= length;
|
||||
emit mediaLengthChanged();
|
||||
}
|
||||
|
||||
void MusicPlayer::reset()
|
||||
{
|
||||
mCurrentMediaItemProgress = 0.0;
|
||||
mCurrentTime = 0.0;
|
||||
emit progressChanged();
|
||||
|
||||
mCurrentMediaItemLength = 0.0;
|
||||
emit mediaLengthChanged();
|
||||
return timeToString(position());
|
||||
}
|
||||
|
||||
void MusicPlayer::clearMediaList()
|
||||
|
|
|
|||
|
|
@ -61,9 +61,6 @@ public slots:
|
|||
void playNext();
|
||||
void playPrevious();
|
||||
|
||||
void onTimeChanged(int time);
|
||||
void onLengthChanged(int length);
|
||||
|
||||
private:
|
||||
void reset();
|
||||
void clearMediaList();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue