Fix seek via mpris
This commit is contained in:
@@ -25,15 +25,18 @@
|
||||
#include "mpdconnection.h"
|
||||
#include "playeradaptor.h"
|
||||
#include "rootadaptor.h"
|
||||
#include "config.h"
|
||||
#ifdef ENABLE_KDE_SUPPORT
|
||||
#include <KDE/KWindowSystem>
|
||||
#endif
|
||||
|
||||
static inline int convertTime(int t)
|
||||
static inline qlonglong convertTime(int t)
|
||||
{
|
||||
return t*1000000;
|
||||
}
|
||||
|
||||
static QString mprisPath;
|
||||
|
||||
Mpris::Mpris(MainWindow *p)
|
||||
: QObject(p)
|
||||
, mw(p)
|
||||
@@ -41,23 +44,22 @@ Mpris::Mpris(MainWindow *p)
|
||||
{
|
||||
QDBusConnection::sessionBus().registerService("org.mpris.MediaPlayer2.cantata");
|
||||
|
||||
// Comes from playeradaptor.h which is auto-generated
|
||||
// in the top-level CMakeLists.txt with qt4_add_dbus_adaptor.
|
||||
new PlayerAdaptor(this);
|
||||
|
||||
// Comes from rootadaptor.h which is auto-generated
|
||||
// in the top-level CMakeLists.txt with qt4_add_dbus_adaptor.
|
||||
new MediaPlayer2Adaptor(this);
|
||||
|
||||
QDBusConnection::sessionBus().registerObject("/org/mpris/MediaPlayer2", this, QDBusConnection::ExportAdaptors);
|
||||
connect(this, SIGNAL(setRandom(bool)), MPDConnection::self(), SLOT(setRandom(bool)));
|
||||
connect(this, SIGNAL(setRepeat(bool)), MPDConnection::self(), SLOT(setRepeat(bool)));
|
||||
connect(this, SIGNAL(setSeek(quint32, quint32)), MPDConnection::self(), SLOT(setSeek(quint32, quint32)));
|
||||
connect(this, SIGNAL(setSeekId(quint32, quint32)), MPDConnection::self(), SLOT(setSeekId(quint32, quint32)));
|
||||
connect(this, SIGNAL(setSeekId(qint32, quint32)), MPDConnection::self(), SLOT(setSeekId(qint32, quint32)));
|
||||
connect(this, SIGNAL(setVolume(int)), MPDConnection::self(), SLOT(setVolume(int)));
|
||||
|
||||
// connect(MPDConnection::self(), SIGNAL(currentSongUpdated(const Song &)), this, SLOT(updateCurrentSong(const Song &)));
|
||||
connect(MPDStatus::self(), SIGNAL(updated()), this, SLOT(updateStatus()));
|
||||
if (mprisPath.isEmpty()) {
|
||||
mprisPath=QLatin1String(CANTATA_REV_URL);
|
||||
mprisPath.replace(".", "/");
|
||||
mprisPath="/"+mprisPath+"/Track/%1";
|
||||
}
|
||||
}
|
||||
|
||||
qlonglong Mpris::Position() const
|
||||
@@ -88,6 +90,7 @@ void Mpris::updateStatus()
|
||||
map.insert("PlaybackStatus", PlaybackStatus());
|
||||
map.insert("CanPlay", CanPlay());
|
||||
map.insert("CanPause", CanPause());
|
||||
map.insert("CanSeek", CanSeek());
|
||||
}
|
||||
if (MPDStatus::self()->timeElapsed()!=status.timeElapsed) {
|
||||
map.insert("Position", convertTime(MPDStatus::self()->timeElapsed()));
|
||||
@@ -123,7 +126,7 @@ QVariantMap Mpris::Metadata() const {
|
||||
QVariantMap metadataMap;
|
||||
if (!currentSong.title.isEmpty() && !currentSong.artist.isEmpty() &&
|
||||
(!currentSong.album.isEmpty() || (currentSong.isStream() && !currentSong.name.isEmpty()))) {
|
||||
metadataMap.insert("mpris:trackid", currentSong.id);
|
||||
metadataMap.insert("mpris:trackid", QVariant::fromValue<QDBusObjectPath>(QDBusObjectPath(mprisPath.arg(currentSong.id))));
|
||||
if (currentSong.time>0) {
|
||||
metadataMap.insert("mpris:length", convertTime(currentSong.time));
|
||||
}
|
||||
|
||||
15
dbus/mpris.h
15
dbus/mpris.h
@@ -28,7 +28,6 @@
|
||||
#include <QStringList>
|
||||
#include <QVariantMap>
|
||||
#include <QApplication>
|
||||
|
||||
#include "song.h"
|
||||
#include "mpdstatus.h"
|
||||
#include "mainwindow.h"
|
||||
@@ -47,6 +46,7 @@ class Mpris : public QObject
|
||||
Q_PROPERTY( bool CanControl READ CanControl )
|
||||
Q_PROPERTY( bool CanPlay READ CanPlay )
|
||||
Q_PROPERTY( bool CanPause READ CanPause )
|
||||
Q_PROPERTY( bool CanSeek READ CanSeek )
|
||||
Q_PROPERTY( bool CanGoNext READ CanGoNext )
|
||||
Q_PROPERTY( bool CanGoPrevious READ CanGoPrevious )
|
||||
Q_PROPERTY( QString PlaybackStatus READ PlaybackStatus )
|
||||
@@ -66,7 +66,6 @@ class Mpris : public QObject
|
||||
|
||||
public:
|
||||
Mpris(MainWindow *p);
|
||||
|
||||
virtual ~Mpris() { }
|
||||
|
||||
// org.mpris.MediaPlayer2.Player
|
||||
@@ -78,8 +77,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void PlayPause() { mw->playPauseTrack(); }
|
||||
void Stop() { mw->stopPlayback(); }
|
||||
void PlayPause() { mw->playPauseTrack(); }
|
||||
void Stop() { mw->stopPlayback(); }
|
||||
|
||||
void Play() {
|
||||
MPDStatus * const status = MPDStatus::self();
|
||||
@@ -89,8 +88,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void Seek(qlonglong) { }
|
||||
void SetPosition(const QDBusObjectPath &, qlonglong) { }
|
||||
void Seek(qlonglong pos) { emit setSeekId(-1, pos/1000000); }
|
||||
void SetPosition(const QDBusObjectPath &, qlonglong pos) {emit setSeekId(-1, pos/1000000); }
|
||||
void OpenUri(const QString &) { }
|
||||
|
||||
QString PlaybackStatus() {
|
||||
@@ -117,6 +116,7 @@ public:
|
||||
bool CanControl() const { return true; }
|
||||
bool CanPlay() const { return MPDState_Playing!=MPDStatus::self()->state() && MPDStatus::self()->playlistLength()>0; }
|
||||
bool CanPause() const { return MPDState_Playing==MPDStatus::self()->state(); }
|
||||
bool CanSeek() const { return -1!=MPDStatus::self()->songId(); }
|
||||
bool CanGoNext() const { return MPDState_Stopped!=MPDStatus::self()->state() && MPDStatus::self()->playlistLength()>1; }
|
||||
bool CanGoPrevious() const { return MPDState_Stopped!=MPDStatus::self()->state() && MPDStatus::self()->playlistLength()>1; }
|
||||
|
||||
@@ -151,8 +151,7 @@ Q_SIGNALS:
|
||||
// org.mpris.MediaPlayer2.Player
|
||||
void setRandom(bool toggle);
|
||||
void setRepeat(bool toggle);
|
||||
void setSeek(quint32 song, quint32 time);
|
||||
void setSeekId(quint32 songId, quint32 time);
|
||||
void setSeekId(qint32 songId, quint32 time);
|
||||
void setVolume(int vol);
|
||||
|
||||
public Q_SLOTS:
|
||||
|
||||
@@ -78,7 +78,7 @@ static QByteArray readFromSocket(MpdSocket &socket)
|
||||
break;
|
||||
}
|
||||
if (++attempt>=constMaxReadAttempts) {
|
||||
qWarning() << "ERROR: Timedout waiting for response";
|
||||
DBUG << "ERROR: Timedout waiting for response";
|
||||
socket.close();
|
||||
return QByteArray();
|
||||
}
|
||||
@@ -440,7 +440,6 @@ MPDConnection::Response MPDConnection::sendCommand(const QByteArray &command, bo
|
||||
// Try one more time...
|
||||
// This scenario, where socket seems to be closed during/after 'write' seems to occiu more often
|
||||
// when dynamizer is running. However, simply reconnecting seems to resolve the issue.
|
||||
qWarning() << "Socket is not connected, so try reconnecting and re-send command";
|
||||
return sendCommand(command, emitErrors, false);
|
||||
}
|
||||
if (emitErrors) {
|
||||
@@ -819,6 +818,12 @@ void MPDConnection::setSeek(quint32 song, quint32 time)
|
||||
|
||||
void MPDConnection::setSeekId(qint32 songId, quint32 time)
|
||||
{
|
||||
if (-1==songId) {
|
||||
songId=currentSongId;
|
||||
}
|
||||
if (-1==songId) {
|
||||
return;
|
||||
}
|
||||
if (songId!=currentSongId) {
|
||||
toggleStopAfterCurrent(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user