Commit 9f8851da authored by Alex Merry's avatar Alex Merry

Fix notification of volume changes and seeks

Setting the volume in MPRIS would previously not update the volume
slider; it now does.  The CanSeek property is also now always set
correctly, and Seeked is emitted when appropriate.
parent b9bb16f0
......@@ -52,14 +52,14 @@ MediaPlayer2Player::MediaPlayer2Player(QObject* parent)
: QDBusAbstractAdaptor(parent)
, m_player(JuK::JuKInstance()->playerManager())
{
connect(m_player, SIGNAL(tick(int)), this, SLOT(tick(int)));
connect(m_player, SIGNAL(signalItemChanged(FileHandle)), this, SLOT(currentSourceChanged()));
connect(m_player, SIGNAL(signalPlay()), this, SLOT(stateUpdated()));
connect(m_player, SIGNAL(signalPause()), this, SLOT(stateUpdated()));
connect(m_player, SIGNAL(signalStop()), this, SLOT(stateUpdated()));
connect(m_player, SIGNAL(totalTimeChanged(int)), this, SLOT(totalTimeChanged()));
// connect(m_player, SIGNAL(seekableChanged(bool)), this, SLOT(seekableChanged(bool)));
// connect(m_player, SIGNAL(volumeChanged(qreal)), this, SLOT(volumeChanged(qreal)));
connect(m_player, SIGNAL(seekableChanged(bool)), this, SLOT(seekableChanged(bool)));
connect(m_player, SIGNAL(volumeChanged(float)), this, SLOT(volumeChanged(float)));
connect(m_player, SIGNAL(seeked(int)), this, SLOT(seeked(int)));
}
MediaPlayer2Player::~MediaPlayer2Player()
......@@ -222,6 +222,10 @@ double MediaPlayer2Player::Volume() const
void MediaPlayer2Player::setVolume(double volume) const
{
if (volume < 0.0)
volume = 0.0;
if (volume > 1.0)
volume = 1.0;
m_player->setVolume(volume);
}
......@@ -255,19 +259,6 @@ bool MediaPlayer2Player::CanControl() const
return true;
}
void MediaPlayer2Player::tick(int newPos)
{
QVariantMap properties;
properties["Position"] = Position();
signalPropertiesChange(properties);
// 200 is the default tick interval set in playermanager.cpp
if (newPos - oldPos > 200 + 250 || newPos < oldPos)
emit Seeked(newPos * 1000);
oldPos = newPos;
}
void MediaPlayer2Player::currentSourceChanged() const
{
QVariantMap properties;
......@@ -298,7 +289,7 @@ void MediaPlayer2Player::seekableChanged(bool seekable) const
signalPropertiesChange(properties);
}
void MediaPlayer2Player::volumeChanged(qreal newVol) const
void MediaPlayer2Player::volumeChanged(float newVol) const
{
Q_UNUSED(newVol)
......@@ -307,6 +298,12 @@ void MediaPlayer2Player::volumeChanged(qreal newVol) const
signalPropertiesChange(properties);
}
void MediaPlayer2Player::seeked(int newPos) const
{
// casts int to uint64
emit Seeked(newPos);
}
void MediaPlayer2Player::signalPropertiesChange(const QVariantMap& properties) const
{
QDBusMessage msg = QDBusMessage::createSignal("/org/mpris/MediaPlayer2",
......
......@@ -89,12 +89,12 @@ class MediaPlayer2Player : public QDBusAbstractAdaptor
void OpenUri(QString Uri) const;
private slots:
void tick(int newPos);
void currentSourceChanged() const;
void stateUpdated() const;
void totalTimeChanged() const;
void seekableChanged(bool seekable) const;
void volumeChanged(qreal newVol) const;
void volumeChanged(float newVol) const;
void seeked(int newPos) const;
private:
void signalPropertiesChange(const QVariantMap& properties) const;
......
......@@ -238,6 +238,7 @@ void PlayerManager::play(const FileHandle &file)
mediaObject->play();
else if(playing()) {
mediaObject->seek(0);
emit seeked(0);
}
else {
m_playlistInterface->playNext();
......@@ -337,6 +338,7 @@ void PlayerManager::seek(int seekTime)
<< "to" << seekTime;
stopCrossfade();
m_media[m_curOutputPath]->seek(seekTime);
emit seeked(seekTime);
}
void PlayerManager::seekForward()
......@@ -344,9 +346,11 @@ void PlayerManager::seekForward()
Phonon::MediaObject *mediaObject = m_media[m_curOutputPath];
const qint64 total = mediaObject->totalTime();
const qint64 newtime = mediaObject->currentTime() + total / 100;
const qint64 seekTo = qMin(total, newtime);
stopCrossfade();
mediaObject->seek(qMin(total, newtime));
mediaObject->seek(seekTo);
emit seeked(seekTo);
}
void PlayerManager::seekBack()
......@@ -354,9 +358,11 @@ void PlayerManager::seekBack()
Phonon::MediaObject *mediaObject = m_media[m_curOutputPath];
const qint64 total = mediaObject->totalTime();
const qint64 newtime = mediaObject->currentTime() - total / 100;
const qint64 seekTo = qMax(qint64(0), newtime);
stopCrossfade();
mediaObject->seek(qMax(qint64(0), newtime));
mediaObject->seek(seekTo);
emit seeked(seekTo);
}
void PlayerManager::playPause()
......@@ -553,6 +559,44 @@ void PlayerManager::slotStateChanged(Phonon::State newstate, Phonon::State oldst
}
}
void PlayerManager::slotSeekableChanged(bool isSeekable)
{
// Use sender() since either media object may have sent the signal.
Phonon::MediaObject *mediaObject = qobject_cast<Phonon::MediaObject *>(sender());
if(!mediaObject)
return;
if(mediaObject != m_media[m_curOutputPath])
return;
emit seekableChanged(isSeekable);
}
void PlayerManager::slotMutedChanged(bool muted)
{
// Use sender() since either output object may have sent the signal.
Phonon::AudioOutput *output = qobject_cast<Phonon::AudioOutput *>(sender());
if(!output)
return;
if(output != m_output[m_curOutputPath])
return;
emit mutedChanged(muted);
}
void PlayerManager::slotVolumeChanged(qreal volume)
{
// Use sender() since either output object may have sent the signal.
Phonon::AudioOutput *output = qobject_cast<Phonon::AudioOutput *>(sender());
if(!output)
return;
if(output != m_output[m_curOutputPath])
return;
emit volumeChanged(volume);
}
////////////////////////////////////////////////////////////////////////////////
// private members
////////////////////////////////////////////////////////////////////////////////
......@@ -582,6 +626,8 @@ void PlayerManager::setup()
for(int i = 0; i < 2; ++i) {
m_output[i] = new Phonon::AudioOutput(Phonon::MusicCategory, this);
connect(m_output[i], SIGNAL(mutedChanged(bool)), SLOT(slotMutedChanged(bool)));
connect(m_output[i], SIGNAL(volumeChanged(qreal)), SLOT(slotVolumeChanged(qreal)));
m_media[i] = new Phonon::MediaObject(this);
m_audioPath[i] = Phonon::createPath(m_media[i], m_output[i]);
......@@ -598,6 +644,7 @@ void PlayerManager::setup()
connect(m_media[i], SIGNAL(totalTimeChanged(qint64)), SLOT(slotLength(qint64)));
connect(m_media[i], SIGNAL(tick(qint64)), SLOT(slotTick(qint64)));
connect(m_media[i], SIGNAL(finished()), SLOT(slotFinished()));
connect(m_media[i], SIGNAL(seekableChanged(bool)), SLOT(slotSeekableChanged(bool)));
}
// initialize action states
......
......@@ -112,6 +112,10 @@ public slots:
signals:
void tick(int time);
void totalTimeChanged(int time);
void mutedChanged(bool muted);
void volumeChanged(float volume);
void seeked(int newPos);
void seekableChanged(bool muted);
void signalPlay();
void signalPause();
......@@ -131,6 +135,9 @@ private slots:
void slotStateChanged(Phonon::State, Phonon::State);
/// Updates the GUI to reflect stopped playback if we're stopped at this point.
void slotUpdateGuiIfStopped();
void slotSeekableChanged(bool);
void slotMutedChanged(bool);
void slotVolumeChanged(qreal);
private:
FileHandle m_file;
......
......@@ -50,22 +50,26 @@ QWidget *TrackPositionAction::createWidget(QWidget *parent)
PlayerManager *player = JuK::JuKInstance()->playerManager();
connect(player, SIGNAL(tick(int)), slider, SLOT(setValue(int)));
connect(player, SIGNAL(seekableChanged(bool)), this, SLOT(seekableChanged(bool)));
connect(player, SIGNAL(totalTimeChanged(int)), this, SLOT(totalTimeChanged(int)));
connect(slider, SIGNAL(sliderMoved(int)), player, SLOT(seek(int)));
return slider;
}
void TrackPositionAction::totalTimeChanged(int ms)
void TrackPositionAction::seekableChanged(bool seekable)
{
slider()->setRange(0, ms);
bool seekable = JuK::JuKInstance()->playerManager()->seekable();
slider()->setEnabled(seekable);
slider()->setToolTip(seekable ?
QString() :
i18n("Seeking is not supported in this file with your audio settings."));
}
void TrackPositionAction::totalTimeChanged(int ms)
{
slider()->setRange(0, ms);
}
VolumeAction::VolumeAction(const QString &text, QObject *parent) :
KAction(text, parent),
m_button(0)
......
......@@ -32,6 +32,7 @@ public:
protected:
virtual QWidget *createWidget(QWidget *parent);
private slots:
void seekableChanged(bool seekable);
void totalTimeChanged(int ms);
};
......
......@@ -72,7 +72,7 @@ VolumePopupButton::VolumePopupButton( QWidget * parent )
m_muteAction->setChecked( player->muted() );
connect( m_muteAction, SIGNAL(toggled(bool)), player, SLOT(setMuted(bool)) );
connect( m_muteAction, SIGNAL(toggled(bool)), this, SLOT(muteStateChanged(bool)) );
connect( player, SIGNAL(mutedChanged(bool)), this, SLOT(muteStateChanged(bool)) );
m_volumeMenu->addAction( sliderActionWidget );
muteBar->addAction( m_muteAction );
......@@ -80,7 +80,7 @@ VolumePopupButton::VolumePopupButton( QWidget * parent )
// set correct icon and label initially
volumeChanged( player->volume() );
connect( m_volumeSlider, SIGNAL(volumeChanged(float)), this, SLOT(volumeChanged(float)) );
connect( player, SIGNAL(volumeChanged(float)), this, SLOT(volumeChanged(float)) );
}
void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment