Inital implementation of mpris2 interface for remote control.
This commit is contained in:
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user