diff options
author | Arno <arno@disconnect.de> | 2017-02-27 12:12:04 +0100 |
---|---|---|
committer | Arno <arno@disconnect.de> | 2017-02-27 12:12:04 +0100 |
commit | a49455204fa38c3237bf00a93e0948f4a25355a4 (patch) | |
tree | ed0644e7650a73c07e7bd9449624ad28c0e2f9a1 /playerwidget.cpp | |
parent | 52384c4685a9d25ceb97b8acc36fe5844ec112b4 (diff) | |
download | BeetPlayer-a49455204fa38c3237bf00a93e0948f4a25355a4.tar.gz BeetPlayer-a49455204fa38c3237bf00a93e0948f4a25355a4.tar.bz2 BeetPlayer-a49455204fa38c3237bf00a93e0948f4a25355a4.zip |
Implement Song Slider
Diffstat (limited to 'playerwidget.cpp')
-rw-r--r-- | playerwidget.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/playerwidget.cpp b/playerwidget.cpp index bfe3815..33d8e9b 100644 --- a/playerwidget.cpp +++ b/playerwidget.cpp @@ -31,6 +31,8 @@ PlayerWidget::PlayerWidget(QWidget *parent) : QWidget(parent){ void PlayerWidget::setupGui(){ //the Player mPlayer = new QMediaPlayer(this); + connect(mPlayer, SIGNAL(positionChanged(qint64)), this, SLOT(setPosition(qint64))); + connect(mPlayer, SIGNAL(durationChanged(qint64)), this, SLOT(setDuration(qint64))); //THE view mView = new BeetView; @@ -71,6 +73,7 @@ void PlayerWidget::setupGui(){ QLabel *l1 = new QLabel(tr("Song")); mSongSlider = new QSlider; mSongSlider->setOrientation(Qt::Horizontal); + connect(mSongSlider, SIGNAL(sliderMoved(int)), this, SLOT(slide(int))); mPos = new QLabel(tr("00:00")); mPos->setFont(QFont("courier")); QHBoxLayout *songSliderL = new QHBoxLayout; @@ -462,6 +465,7 @@ void PlayerWidget::playCurrent(const QModelIndex &index){ void PlayerWidget::play(const QString &fullPath){ mPlayer->setMedia(QUrl::fromLocalFile(fullPath)); + mPlayA->trigger(); } @@ -504,3 +508,23 @@ void PlayerWidget::advance(int numSongs){ play(fp); } } + +void PlayerWidget::slide(int value){ + qint64 newValue = value * 1000; + mPlayer->setPosition(newValue); +} + +void PlayerWidget::setPosition(qint64 pos){ + int curPos = pos / 1000; + mSongSlider->setValue(curPos); + int minutes = curPos / 60; + int seconds = curPos % 60; + QString posString = QString("%1:%2").arg(minutes, 2, 10, QChar('0')).arg(seconds, 2, 10, QChar('0')); + mPos->setText(posString); +} + +void PlayerWidget::setDuration(qint64 dur){ + qint64 durSecs = dur / 1000; + mSongSlider->setMinimum(0); + mSongSlider->setMaximum(durSecs); +} |