Inital implementation of mpris2 interface for remote control.
This commit is contained in:
@@ -14,7 +14,7 @@ include(KDECMakeSettings)
|
|||||||
include(KDECompilerSettings NO_POLICY_SCOPE)
|
include(KDECompilerSettings NO_POLICY_SCOPE)
|
||||||
include(FeatureSummary)
|
include(FeatureSummary)
|
||||||
|
|
||||||
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core Multimedia Network)
|
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core Multimedia Network DBus)
|
||||||
|
|
||||||
find_package(KF5 ${KF_MIN_VERSION} REQUIRED COMPONENTS
|
find_package(KF5 ${KF_MIN_VERSION} REQUIRED COMPONENTS
|
||||||
CoreAddons
|
CoreAddons
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ set( simplecastengine_SRCS
|
|||||||
minimediaplayer.cpp
|
minimediaplayer.cpp
|
||||||
simplecastservice.cpp
|
simplecastservice.cpp
|
||||||
simplecasttcpservice.cpp
|
simplecasttcpservice.cpp
|
||||||
|
mprisinterface.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(plasma_engine_simplecast ${simplecastengine_SRCS})
|
add_library(plasma_engine_simplecast ${simplecastengine_SRCS})
|
||||||
@@ -14,6 +15,7 @@ target_link_libraries( plasma_engine_simplecast
|
|||||||
Qt5::Core
|
Qt5::Core
|
||||||
Qt5::Multimedia
|
Qt5::Multimedia
|
||||||
Qt5::Network
|
Qt5::Network
|
||||||
|
Qt5::DBus
|
||||||
KF5::Plasma
|
KF5::Plasma
|
||||||
KF5::Service
|
KF5::Service
|
||||||
KF5::I18n
|
KF5::I18n
|
||||||
|
|||||||
@@ -58,6 +58,26 @@ bool MiniMediaPlayer::nextTrack()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qint64 MiniMediaPlayer::getCurrentPosition()
|
||||||
|
{
|
||||||
|
return m_player->position();
|
||||||
|
}
|
||||||
|
|
||||||
|
qint64 MiniMediaPlayer::getTrackDuration()
|
||||||
|
{
|
||||||
|
return m_player->duration();
|
||||||
|
}
|
||||||
|
|
||||||
|
int MiniMediaPlayer::getVolume()
|
||||||
|
{
|
||||||
|
return m_player->volume();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MiniMediaPlayer::setVolume(int volume)
|
||||||
|
{
|
||||||
|
m_player->setVolume(volume);
|
||||||
|
}
|
||||||
|
|
||||||
bool MiniMediaPlayer::playPauseTrack(bool playing)
|
bool MiniMediaPlayer::playPauseTrack(bool playing)
|
||||||
{
|
{
|
||||||
if(m_player->state() == QMediaPlayer::State::PlayingState && !playing)
|
if(m_player->state() == QMediaPlayer::State::PlayingState && !playing)
|
||||||
|
|||||||
@@ -43,6 +43,14 @@ public:
|
|||||||
|
|
||||||
bool playPauseTrack(bool playing);
|
bool playPauseTrack(bool playing);
|
||||||
|
|
||||||
|
qint64 getCurrentPosition();
|
||||||
|
|
||||||
|
qint64 getTrackDuration();
|
||||||
|
|
||||||
|
int getVolume();
|
||||||
|
|
||||||
|
void setVolume(int volume);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void playStateChanged(bool isPlaying);
|
void playStateChanged(bool isPlaying);
|
||||||
void playlistChanged(QStringList trackTitles);
|
void playlistChanged(QStringList trackTitles);
|
||||||
|
|||||||
183
src/mprisinterface.cpp
Normal file
183
src/mprisinterface.cpp
Normal file
@@ -0,0 +1,183 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 Kevin Whitaker <eyecreate@eyecreate.org>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "mprisinterface.h"
|
||||||
|
#include <qcryptographichash.h>
|
||||||
|
|
||||||
|
MPRISInterface::MPRISInterface(QObject* parent) : QDBusAbstractAdaptor(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MPRISInterface::CanQuit()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MPRISInterface::CanRaise()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MPRISInterface::HasTrackList()
|
||||||
|
{
|
||||||
|
return false; //TODO:this might have value implementing.
|
||||||
|
}
|
||||||
|
|
||||||
|
QString MPRISInterface::Identity()
|
||||||
|
{
|
||||||
|
return "Simple Cast";
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList MPRISInterface::SupportedMimeTypes()
|
||||||
|
{
|
||||||
|
return {"audio/ogg","audio/mpeg","audio/webm"};
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList MPRISInterface::SupportedUriSchemes()
|
||||||
|
{
|
||||||
|
return {"https","http"};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
MPRISPlayerInterface::MPRISPlayerInterface(MiniMediaPlayer *player,QObject* parent) : QDBusAbstractAdaptor(parent),player(player)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MPRISPlayerInterface::CanControl()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MPRISPlayerInterface::CanGoNext()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MPRISPlayerInterface::CanGoPrevious()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MPRISPlayerInterface::CanSeek()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MPRISPlayerInterface::CanPause()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MPRISPlayerInterface::CanPlay()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
double MPRISPlayerInterface::MaximumRate()
|
||||||
|
{
|
||||||
|
return 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
double MPRISPlayerInterface::MinimumRate()
|
||||||
|
{
|
||||||
|
return 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MPRISPlayerInterface::OpenUri(QString uri)
|
||||||
|
{
|
||||||
|
//TODO:this might be another way to add tracks
|
||||||
|
}
|
||||||
|
|
||||||
|
void MPRISPlayerInterface::Next()
|
||||||
|
{
|
||||||
|
player->nextTrack();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MPRISPlayerInterface::Pause()
|
||||||
|
{
|
||||||
|
player->playPauseTrack(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MPRISPlayerInterface::Play()
|
||||||
|
{
|
||||||
|
player->playPauseTrack(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MPRISPlayerInterface::PlayPause()
|
||||||
|
{
|
||||||
|
player->playPauseTrack(!player->isPlaying());
|
||||||
|
}
|
||||||
|
|
||||||
|
void MPRISPlayerInterface::Stop()
|
||||||
|
{
|
||||||
|
//TODO: think if worth implementing.
|
||||||
|
}
|
||||||
|
|
||||||
|
QString MPRISPlayerInterface::PlaybackStatus()
|
||||||
|
{
|
||||||
|
if(player->getTrackNames().size() == 0)
|
||||||
|
{
|
||||||
|
return "Stopped";
|
||||||
|
}
|
||||||
|
else if(player->isPlaying()) {
|
||||||
|
return "Playing";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return "Paused";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
qlonglong MPRISPlayerInterface::Position()
|
||||||
|
{
|
||||||
|
return player->getCurrentPosition() * 1000; //milliseconds to microseconds
|
||||||
|
}
|
||||||
|
|
||||||
|
double MPRISPlayerInterface::Rate()
|
||||||
|
{
|
||||||
|
return 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
double MPRISPlayerInterface::Volume()
|
||||||
|
{
|
||||||
|
return player->getVolume();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MPRISPlayerInterface::setVolume(double volume)
|
||||||
|
{
|
||||||
|
if(volume < 0) player->setVolume(0);
|
||||||
|
player->setVolume(volume*100); //QMediaPlayer uses 0 to 100
|
||||||
|
}
|
||||||
|
|
||||||
|
QMap<QString, QDBusVariant> MPRISPlayerInterface::Metadata()
|
||||||
|
{
|
||||||
|
QMap<QString,QDBusVariant> map;
|
||||||
|
map.insert("mpris:trackid",QDBusVariant("org.mpris.MediaPlayer2.simplecast.Player."+QString(QCryptographicHash::hash(player->getTrackNames()[0].toUtf8(),QCryptographicHash::Algorithm::Md5))));
|
||||||
|
map.insert("mpris:length",QDBusVariant(player->getTrackDuration()*1000));
|
||||||
|
map.insert("xesam:title",QDBusVariant(player->getTrackNames()[0]));
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
103
src/mprisinterface.h
Normal file
103
src/mprisinterface.h
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 Kevin Whitaker <eyecreate@eyecreate.org>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MPRISINTERFACE_H
|
||||||
|
#define MPRISINTERFACE_H
|
||||||
|
|
||||||
|
#include "minimediaplayer.h"
|
||||||
|
#include <QtDBus/QDBusAbstractAdaptor>
|
||||||
|
#include <QtDBus/QDBusConnection>
|
||||||
|
#include <QtDBus/QDBusObjectPath>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple DBus interface which registers and provides simple controls over media playing.
|
||||||
|
*/
|
||||||
|
class MPRISInterface : public QDBusAbstractAdaptor
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_CLASSINFO("D-Bus Interface","org.mpris.MediaPlayer2")
|
||||||
|
Q_PROPERTY(bool CanQuit READ CanQuit)
|
||||||
|
Q_PROPERTY(bool CanRaise READ CanRaise)
|
||||||
|
Q_PROPERTY(bool HasTrackList READ HasTrackList)
|
||||||
|
Q_PROPERTY(QString Identity READ Identity)
|
||||||
|
Q_PROPERTY(QStringList SupportedUriSchemes READ SupportedUriSchemes)
|
||||||
|
Q_PROPERTY(QStringList SupportedMimeTypes READ SupportedMimeTypes)
|
||||||
|
public:
|
||||||
|
MPRISInterface(QObject *parent = 0);
|
||||||
|
bool CanQuit();
|
||||||
|
bool CanRaise();
|
||||||
|
bool HasTrackList();
|
||||||
|
QString Identity();
|
||||||
|
QStringList SupportedUriSchemes();
|
||||||
|
QStringList SupportedMimeTypes();
|
||||||
|
public slots:
|
||||||
|
Q_NOREPLY void Raise() {};
|
||||||
|
Q_NOREPLY void Quit() {};
|
||||||
|
};
|
||||||
|
|
||||||
|
class MPRISPlayerInterface : public QDBusAbstractAdaptor
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_CLASSINFO("D-Bus Interface","org.mpris.MediaPlayer2.Player")
|
||||||
|
Q_PROPERTY(QString PlaybackStatus READ PlaybackStatus)
|
||||||
|
Q_PROPERTY(double Rate READ Rate WRITE setRate)
|
||||||
|
Q_PROPERTY(QMap<QString,QDBusVariant>Metadata READ Metadata)
|
||||||
|
Q_PROPERTY(double Volume READ Volume WRITE setVolume)
|
||||||
|
Q_PROPERTY(qlonglong Position READ Position)
|
||||||
|
Q_PROPERTY(double MinimumRate READ MinimumRate)
|
||||||
|
Q_PROPERTY(double MaximumRate READ MaximumRate)
|
||||||
|
Q_PROPERTY(bool CanGoNext READ CanGoNext)
|
||||||
|
Q_PROPERTY(bool CanGoPrevious READ CanGoPrevious)
|
||||||
|
Q_PROPERTY(bool CanPlay READ CanPlay)
|
||||||
|
Q_PROPERTY(bool CanPause READ CanPause)
|
||||||
|
Q_PROPERTY(bool CanSeek READ CanSeek)
|
||||||
|
Q_PROPERTY(bool CanControl READ CanControl)
|
||||||
|
public:
|
||||||
|
MPRISPlayerInterface(MiniMediaPlayer *player,QObject *parent = 0);
|
||||||
|
QString PlaybackStatus();
|
||||||
|
double Rate();
|
||||||
|
void setRate(double rate) {};
|
||||||
|
QMap<QString,QDBusVariant> Metadata();
|
||||||
|
double Volume();
|
||||||
|
void setVolume(double volume);
|
||||||
|
qlonglong Position();
|
||||||
|
double MinimumRate();
|
||||||
|
double MaximumRate();
|
||||||
|
bool CanGoNext();
|
||||||
|
bool CanGoPrevious();
|
||||||
|
bool CanPlay();
|
||||||
|
bool CanPause();
|
||||||
|
bool CanSeek();
|
||||||
|
bool CanControl();
|
||||||
|
public slots:
|
||||||
|
Q_NOREPLY void Next();
|
||||||
|
Q_NOREPLY void Previous() {};
|
||||||
|
Q_NOREPLY void Pause();
|
||||||
|
Q_NOREPLY void PlayPause();
|
||||||
|
Q_NOREPLY void Stop();
|
||||||
|
Q_NOREPLY void Play();
|
||||||
|
Q_NOREPLY void Seek(qlonglong offset) {};
|
||||||
|
Q_NOREPLY void SetPosition(QDBusObjectPath trackId,qlonglong position) {};
|
||||||
|
Q_NOREPLY void OpenUri(QString uri);
|
||||||
|
signals:
|
||||||
|
void Seeked(qlonglong position);
|
||||||
|
private:
|
||||||
|
MiniMediaPlayer *player;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MPRISINTERFACE_H
|
||||||
@@ -25,8 +25,16 @@ SimpleCastEngine::SimpleCastEngine(QObject *parent, const QVariantList &args)
|
|||||||
: Plasma::DataEngine(parent,args), player(new MiniMediaPlayer(this))
|
: Plasma::DataEngine(parent,args), player(new MiniMediaPlayer(this))
|
||||||
{
|
{
|
||||||
Q_UNUSED(args)
|
Q_UNUSED(args)
|
||||||
|
|
||||||
|
rootInt = new MPRISInterface(this);
|
||||||
|
playerInt = new MPRISPlayerInterface(player,this);
|
||||||
|
QDBusConnection::sessionBus().registerObject("/org/mpris/MediaPlayer2","org.mpris.MediaPlayer2",rootInt);
|
||||||
|
QDBusConnection::sessionBus().registerObject("/org/mpris/MediaPlayer2","org.mpris.MediaPlayer2.Player",playerInt);
|
||||||
|
QDBusConnection::sessionBus().registerService("org.mpris.MediaPlayer2.Player.simplecast");
|
||||||
|
|
||||||
tcpService = new SimpleCastTcpService(player,this);
|
tcpService = new SimpleCastTcpService(player,this);
|
||||||
setMinimumPollingInterval(333);
|
setMinimumPollingInterval(333);
|
||||||
|
|
||||||
connect(player,SIGNAL(playStateChanged(bool)),this,SLOT(playStateChanged(bool)));
|
connect(player,SIGNAL(playStateChanged(bool)),this,SLOT(playStateChanged(bool)));
|
||||||
connect(player,SIGNAL(trackDurationChanged(qint64)),this,SLOT(durationChanged(qint64)));
|
connect(player,SIGNAL(trackDurationChanged(qint64)),this,SLOT(durationChanged(qint64)));
|
||||||
connect(player,SIGNAL(trackPositionChanged(qint64)),this,SLOT(positionChanged(qint64)));
|
connect(player,SIGNAL(trackPositionChanged(qint64)),this,SLOT(positionChanged(qint64)));
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#include <qt5/QtCore/QString>
|
#include <qt5/QtCore/QString>
|
||||||
#include "minimediaplayer.h"
|
#include "minimediaplayer.h"
|
||||||
#include "simplecasttcpservice.h"
|
#include "simplecasttcpservice.h"
|
||||||
|
#include "mprisinterface.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple Cast Engine is a Plasma DataEngine that conveys that status on the media player casting to to other code like Plasmoids.
|
* Simple Cast Engine is a Plasma DataEngine that conveys that status on the media player casting to to other code like Plasmoids.
|
||||||
@@ -47,6 +48,8 @@ protected:
|
|||||||
bool sourceRequestEvent(const QString &source) override;
|
bool sourceRequestEvent(const QString &source) override;
|
||||||
bool updateSourceEvent(const QString &source) override;
|
bool updateSourceEvent(const QString &source) override;
|
||||||
SimpleCastTcpService *tcpService;
|
SimpleCastTcpService *tcpService;
|
||||||
|
MPRISInterface *rootInt;
|
||||||
|
MPRISPlayerInterface *playerInt;
|
||||||
MiniMediaPlayer *player;
|
MiniMediaPlayer *player;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user