diff options
-rw-r--r-- | examples/player/mediaapp.cpp | 22 | ||||
-rw-r--r-- | examples/player/mediaapp.h | 2 | ||||
-rw-r--r-- | examples/player/player.cpp | 28 | ||||
-rw-r--r-- | examples/player/player.h | 2 |
4 files changed, 53 insertions, 1 deletions
diff --git a/examples/player/mediaapp.cpp b/examples/player/mediaapp.cpp index 75a4d5c..7802b1e 100644 --- a/examples/player/mediaapp.cpp +++ b/examples/player/mediaapp.cpp @@ -99,6 +99,9 @@ void MediaApp::onStateChanged() m_pauseButton->setEnabled(newState == QGst::StatePlaying); m_stopButton->setEnabled(newState != QGst::StateNull); m_positionSlider->setEnabled(newState != QGst::StateNull); + m_volumeSlider->setEnabled(newState != QGst::StateNull); + m_volumeLabel->setEnabled(newState != QGst::StateNull); + m_volumeSlider->setValue(m_player->volume()); //if we are in Null state, call onPositionChanged() to restore //the position of the slider and the text on the label @@ -155,6 +158,8 @@ void MediaApp::showControls(bool show) m_stopButton->setVisible(show); m_fullScreenButton->setVisible(show); m_positionSlider->setVisible(show); + m_volumeSlider->setVisible(show); + m_volumeLabel->setVisible(show); m_positionLabel->setVisible(show); } @@ -193,6 +198,14 @@ void MediaApp::createUI(QBoxLayout *appLayout) connect(m_positionSlider, SIGNAL(sliderMoved(int)), this, SLOT(setPosition(int))); + m_volumeSlider = new QSlider(Qt::Horizontal); + m_volumeSlider->setTickPosition(QSlider::TicksLeft); + m_volumeSlider->setTickInterval(2); + m_volumeSlider->setMaximum(10); + m_volumeSlider->setMaximumSize(64,32); + + connect(m_volumeSlider, SIGNAL(sliderMoved(int)), m_player, SLOT(setVolume(int))); + QGridLayout *posLayout = new QGridLayout; posLayout->addWidget(m_positionLabel, 1, 0); posLayout->addWidget(m_positionSlider, 1, 1, 1, 2); @@ -215,8 +228,15 @@ void MediaApp::createUI(QBoxLayout *appLayout) m_fullScreenButton = initButton(QStyle::SP_TitleBarMaxButton, tr("Fullscreen"), this, SLOT(toggleFullScreen()), btnLayout); - btnLayout->addStretch(); + + m_volumeLabel = new QLabel(); + m_volumeLabel->setPixmap( + style()->standardIcon(QStyle::SP_MediaVolume).pixmap(QSize(32, 32), + QIcon::Normal, QIcon::On)); + + btnLayout->addWidget(m_volumeLabel); + btnLayout->addWidget(m_volumeSlider); appLayout->addLayout(btnLayout); } diff --git a/examples/player/mediaapp.h b/examples/player/mediaapp.h index 7fbf20a..2e50a15 100644 --- a/examples/player/mediaapp.h +++ b/examples/player/mediaapp.h @@ -67,7 +67,9 @@ private: QToolButton *m_pauseButton; QToolButton *m_stopButton; QSlider *m_positionSlider; + QSlider *m_volumeSlider; QLabel *m_positionLabel; + QLabel *m_volumeLabel; QTimer m_fullScreenTimer; }; diff --git a/examples/player/player.cpp b/examples/player/player.cpp index 73266f0..6266644 100644 --- a/examples/player/player.cpp +++ b/examples/player/player.cpp @@ -27,6 +27,7 @@ #include <QGst/Query> #include <QGst/ClockTime> #include <QGst/Event> +#include <QGst/StreamVolume> Player::Player(QWidget *parent) : QGst::Ui::VideoWidget(parent) @@ -97,6 +98,33 @@ void Player::setPosition(const QTime & pos) m_pipeline->sendEvent(evt); } +int Player::volume() const +{ + if (m_pipeline) { + QGst::StreamVolumePtr svp = + m_pipeline.dynamicCast<QGst::StreamVolume>(); + + if (svp) { + return svp->volume(QGst::StreamVolumeFormatCubic) * 10; + } + } + + return 0; +} + + +void Player::setVolume(int volume) +{ + if (m_pipeline) { + QGst::StreamVolumePtr svp = + m_pipeline.dynamicCast<QGst::StreamVolume>(); + + if(svp) { + svp->setVolume((double)volume / 10, QGst::StreamVolumeFormatCubic); + } + } +} + QTime Player::length() const { if (m_pipeline) { diff --git a/examples/player/player.h b/examples/player/player.h index 1110e8c..3a42ca2 100644 --- a/examples/player/player.h +++ b/examples/player/player.h @@ -35,6 +35,7 @@ public: QTime position() const; void setPosition(const QTime & pos); + int volume() const; QTime length() const; QGst::State state() const; @@ -43,6 +44,7 @@ public Q_SLOTS: void play(); void pause(); void stop(); + void setVolume(int volume); Q_SIGNALS: void positionChanged(); |