diff options
-rw-r--r-- | playerwidget.cpp | 24 | ||||
-rw-r--r-- | playerwidget.h | 3 |
2 files changed, 27 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); +} diff --git a/playerwidget.h b/playerwidget.h index e828748..0dd2671 100644 --- a/playerwidget.h +++ b/playerwidget.h @@ -37,6 +37,9 @@ class PlayerWidget : public QWidget { void volumeChanged(int volume); void next(); void previous(); + void setPosition(qint64 pos); + void setDuration(qint64 dur); + void slide(int value); private: void setupGui(); |