some more work on the kodi plugin to follow the mediacontroller interface
This commit is contained in:
parent
ac48210953
commit
b1e9c740bf
@ -104,9 +104,7 @@ DeviceManager::DeviceSetupStatus DevicePluginKodi::setupDevice(Device *device)
|
|||||||
connect(kodi, &Kodi::actionExecuted, this, &DevicePluginKodi::onActionExecuted);
|
connect(kodi, &Kodi::actionExecuted, this, &DevicePluginKodi::onActionExecuted);
|
||||||
connect(kodi, &Kodi::versionDataReceived, this, &DevicePluginKodi::versionDataReceived);
|
connect(kodi, &Kodi::versionDataReceived, this, &DevicePluginKodi::versionDataReceived);
|
||||||
connect(kodi, &Kodi::updateDataReceived, this, &DevicePluginKodi::onSetupFinished);
|
connect(kodi, &Kodi::updateDataReceived, this, &DevicePluginKodi::onSetupFinished);
|
||||||
connect(kodi, &Kodi::onPlayerPlay, this, &DevicePluginKodi::onPlayerPlay);
|
connect(kodi, &Kodi::playbackStatusChanged, this, &DevicePluginKodi::onPlaybackStatusChanged);
|
||||||
connect(kodi, &Kodi::onPlayerPause, this, &DevicePluginKodi::onPlayerPause);
|
|
||||||
connect(kodi, &Kodi::onPlayerStop, this, &DevicePluginKodi::onPlayerStop);
|
|
||||||
|
|
||||||
m_kodis.insert(kodi, device);
|
m_kodis.insert(kodi, device);
|
||||||
m_asyncSetups.append(kodi);
|
m_asyncSetups.append(kodi);
|
||||||
@ -167,25 +165,25 @@ DeviceManager::DeviceError DevicePluginKodi::executeAction(Device *device, const
|
|||||||
} else if (action.actionTypeId() == kodiAudioLibraryActionTypeId) {
|
} else if (action.actionTypeId() == kodiAudioLibraryActionTypeId) {
|
||||||
kodi->audioLibrary(action.param(kodiAudioCommandParamTypeId).value().toString(), action.id());
|
kodi->audioLibrary(action.param(kodiAudioCommandParamTypeId).value().toString(), action.id());
|
||||||
return DeviceManager::DeviceErrorAsync;
|
return DeviceManager::DeviceErrorAsync;
|
||||||
} else if(action.actionTypeId() == skipBackActionTypeId) {
|
} else if(action.actionTypeId() == kodiSkipBackActionTypeId) {
|
||||||
kodi->pressButton("skipprevious", action.id());
|
kodi->pressButton("skipprevious", action.id());
|
||||||
return DeviceManager::DeviceErrorAsync;
|
return DeviceManager::DeviceErrorAsync;
|
||||||
} else if(action.actionTypeId() == rewindActionTypeId) {
|
} else if(action.actionTypeId() == kodiRewindActionTypeId) {
|
||||||
kodi->pressButton("rewind", action.id());
|
kodi->pressButton("rewind", action.id());
|
||||||
return DeviceManager::DeviceErrorAsync;
|
return DeviceManager::DeviceErrorAsync;
|
||||||
} else if(action.actionTypeId() == stopActionTypeId) {
|
} else if(action.actionTypeId() == kodiStopActionTypeId) {
|
||||||
kodi->pressButton("stop", action.id());
|
kodi->pressButton("stop", action.id());
|
||||||
return DeviceManager::DeviceErrorAsync;
|
return DeviceManager::DeviceErrorAsync;
|
||||||
} else if(action.actionTypeId() == playActionTypeId) {
|
} else if(action.actionTypeId() == kodiPlayActionTypeId) {
|
||||||
kodi->pressButton("play", action.id());
|
kodi->pressButton("play", action.id());
|
||||||
return DeviceManager::DeviceErrorAsync;
|
return DeviceManager::DeviceErrorAsync;
|
||||||
} else if(action.actionTypeId() == pauseActionTypeId) {
|
} else if(action.actionTypeId() == kodiPauseActionTypeId) {
|
||||||
kodi->pressButton("pause", action.id());
|
kodi->pressButton("pause", action.id());
|
||||||
return DeviceManager::DeviceErrorAsync;
|
return DeviceManager::DeviceErrorAsync;
|
||||||
} else if(action.actionTypeId() == fastForwardActionTypeId) {
|
} else if(action.actionTypeId() == kodiFastForwardActionTypeId) {
|
||||||
kodi->pressButton("fastforward", action.id());
|
kodi->pressButton("fastforward", action.id());
|
||||||
return DeviceManager::DeviceErrorAsync;
|
return DeviceManager::DeviceErrorAsync;
|
||||||
} else if(action.actionTypeId() == skipNextActionTypeId) {
|
} else if(action.actionTypeId() == kodiSkipNextActionTypeId) {
|
||||||
kodi->pressButton("skipnext", action.id());
|
kodi->pressButton("skipnext", action.id());
|
||||||
return DeviceManager::DeviceErrorAsync;
|
return DeviceManager::DeviceErrorAsync;
|
||||||
} else {
|
} else {
|
||||||
@ -309,24 +307,18 @@ void DevicePluginKodi::onSetupFinished(const QVariantMap &data)
|
|||||||
kodi->showNotification("Connected", 2000, "info", ActionId());
|
kodi->showNotification("Connected", 2000, "info", ActionId());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginKodi::onPlayerPlay()
|
void DevicePluginKodi::onPlaybackStatusChanged(const QString &playbackStatus)
|
||||||
{
|
{
|
||||||
Kodi *kodi = static_cast<Kodi *>(sender());
|
Kodi *kodi = static_cast<Kodi *>(sender());
|
||||||
Device *device = m_kodis.value(kodi);
|
Device *device = m_kodis.value(kodi);
|
||||||
emit emitEvent(Event(kodiOnPlayerPlayEventTypeId, device->id()));
|
device->setStateValue(kodiPlaybackStatusStateTypeId, playbackStatus);
|
||||||
}
|
// legacy events
|
||||||
|
if (playbackStatus == "PLAYING") {
|
||||||
void DevicePluginKodi::onPlayerPause()
|
emit emitEvent(Event(kodiOnPlayerPlayEventTypeId, device->id()));
|
||||||
{
|
} else if (playbackStatus == "PAUSED") {
|
||||||
Kodi *kodi = static_cast<Kodi *>(sender());
|
emit emitEvent(Event(kodiOnPlayerPauseEventTypeId, device->id()));
|
||||||
Device *device = m_kodis.value(kodi);
|
} else {
|
||||||
emit emitEvent(Event(kodiOnPlayerPauseEventTypeId, device->id()));
|
emit emitEvent(Event(kodiOnPlayerStopEventTypeId, device->id()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginKodi::onPlayerStop()
|
|
||||||
{
|
|
||||||
Kodi *kodi = static_cast<Kodi *>(sender());
|
|
||||||
Device *device = m_kodis.value(kodi);
|
|
||||||
emit emitEvent(Event(kodiOnPlayerStopEventTypeId, device->id()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -61,9 +61,7 @@ private slots:
|
|||||||
void versionDataReceived(const QVariantMap &data);
|
void versionDataReceived(const QVariantMap &data);
|
||||||
void onSetupFinished(const QVariantMap &data);
|
void onSetupFinished(const QVariantMap &data);
|
||||||
|
|
||||||
void onPlayerPlay();
|
void onPlaybackStatusChanged(const QString &playbackStatus);
|
||||||
void onPlayerPause();
|
|
||||||
void onPlayerStop();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DEVICEPLUGINKODI_H
|
#endif // DEVICEPLUGINKODI_H
|
||||||
|
|||||||
@ -21,6 +21,8 @@
|
|||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#include "kodi.h"
|
#include "kodi.h"
|
||||||
|
#include <QDebug>
|
||||||
|
#include "extern-plugininfo.h"
|
||||||
|
|
||||||
Kodi::Kodi(const QHostAddress &hostAddress, const int &port, QObject *parent) :
|
Kodi::Kodi(const QHostAddress &hostAddress, const int &port, QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
@ -36,9 +38,9 @@ Kodi::Kodi(const QHostAddress &hostAddress, const int &port, QObject *parent) :
|
|||||||
connect(m_jsonHandler, &KodiJsonHandler::versionDataReceived, this, &Kodi::versionDataReceived);
|
connect(m_jsonHandler, &KodiJsonHandler::versionDataReceived, this, &Kodi::versionDataReceived);
|
||||||
connect(m_jsonHandler, &KodiJsonHandler::updateDataReceived, this, &Kodi::updateDataReceived);
|
connect(m_jsonHandler, &KodiJsonHandler::updateDataReceived, this, &Kodi::updateDataReceived);
|
||||||
connect(m_jsonHandler, &KodiJsonHandler::updateDataReceived, this, &Kodi::onUpdateFinished);
|
connect(m_jsonHandler, &KodiJsonHandler::updateDataReceived, this, &Kodi::onUpdateFinished);
|
||||||
connect(m_jsonHandler, &KodiJsonHandler::onPlayerPlay, this, &Kodi::onPlayerPlay);
|
connect(m_jsonHandler, &KodiJsonHandler::playbackStatusChanged, this, &Kodi::playbackStatusChanged);
|
||||||
connect(m_jsonHandler, &KodiJsonHandler::onPlayerPause, this, &Kodi::onPlayerPause);
|
connect(m_jsonHandler, &KodiJsonHandler::activePlayersChanged, this, &Kodi::activePlayersChanged);
|
||||||
connect(m_jsonHandler, &KodiJsonHandler::onPlayerStop, this, &Kodi::onPlayerStop);
|
connect(m_jsonHandler, &KodiJsonHandler::playerPropertiesReveived, this, &Kodi::playerPropertiesReceived);
|
||||||
}
|
}
|
||||||
|
|
||||||
QHostAddress Kodi::hostAddress() const
|
QHostAddress Kodi::hostAddress() const
|
||||||
@ -157,6 +159,9 @@ void Kodi::update()
|
|||||||
params.insert("properties", properties);
|
params.insert("properties", properties);
|
||||||
|
|
||||||
m_jsonHandler->sendData("Application.GetProperties", params, ActionId());
|
m_jsonHandler->sendData("Application.GetProperties", params, ActionId());
|
||||||
|
|
||||||
|
params.clear();
|
||||||
|
m_jsonHandler->sendData("Player.GetActivePlayers", params, ActionId());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Kodi::checkVersion()
|
void Kodi::checkVersion()
|
||||||
@ -185,6 +190,7 @@ void Kodi::onVolumeChanged(const int &volume, const bool &muted)
|
|||||||
|
|
||||||
void Kodi::onUpdateFinished(const QVariantMap &data)
|
void Kodi::onUpdateFinished(const QVariantMap &data)
|
||||||
{
|
{
|
||||||
|
qCDebug(dcKodi()) << "update finished:" << data;
|
||||||
if (data.contains("volume")) {
|
if (data.contains("volume")) {
|
||||||
m_volume = data.value("volume").toInt();
|
m_volume = data.value("volume").toInt();
|
||||||
}
|
}
|
||||||
@ -193,3 +199,32 @@ void Kodi::onUpdateFinished(const QVariantMap &data)
|
|||||||
}
|
}
|
||||||
emit stateChanged();
|
emit stateChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Kodi::activePlayersChanged(const QVariantList &data)
|
||||||
|
{
|
||||||
|
qCDebug(dcKodi()) << "active players changed" << data.count();
|
||||||
|
m_activePlayerCount = data.count();
|
||||||
|
if (m_activePlayerCount == 0) {
|
||||||
|
emit playbackStatusChanged("STOPPED");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int activePlayer = data.first().toMap().value("playerid").toInt();
|
||||||
|
QVariantMap params;
|
||||||
|
params.insert("playerid", activePlayer);
|
||||||
|
QVariantList properties;
|
||||||
|
properties.append("speed");
|
||||||
|
params.insert("properties", properties);
|
||||||
|
m_jsonHandler->sendData("Player.GetProperties", params, ActionId());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Kodi::playerPropertiesReceived(const QVariantMap &properties)
|
||||||
|
{
|
||||||
|
qCDebug(dcKodi()) << "player props received" << properties;
|
||||||
|
if (m_activePlayerCount > 0) {
|
||||||
|
if (properties.value("speed").toDouble() > 0) {
|
||||||
|
emit playbackStatusChanged("PLAYING");
|
||||||
|
} else {
|
||||||
|
emit playbackStatusChanged("PAUSED");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
10
kodi/kodi.h
10
kodi/kodi.h
@ -66,6 +66,7 @@ private:
|
|||||||
KodiJsonHandler *m_jsonHandler;
|
KodiJsonHandler *m_jsonHandler;
|
||||||
bool m_muted;
|
bool m_muted;
|
||||||
int m_volume;
|
int m_volume;
|
||||||
|
int m_activePlayerCount = 0; // if it's > 0, there is something playing (either music or video or slideshow)
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void connectionStatusChanged();
|
void connectionStatusChanged();
|
||||||
@ -73,16 +74,13 @@ signals:
|
|||||||
void actionExecuted(const ActionId &actionId, const bool &success);
|
void actionExecuted(const ActionId &actionId, const bool &success);
|
||||||
void updateDataReceived(const QVariantMap &data);
|
void updateDataReceived(const QVariantMap &data);
|
||||||
void versionDataReceived(const QVariantMap &data);
|
void versionDataReceived(const QVariantMap &data);
|
||||||
|
void playbackStatusChanged(const QString &playbackState);
|
||||||
void onPlayerPlay();
|
|
||||||
void onPlayerPause();
|
|
||||||
void onPlayerStop();
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onVolumeChanged(const int &volume, const bool &muted);
|
void onVolumeChanged(const int &volume, const bool &muted);
|
||||||
void onUpdateFinished(const QVariantMap &data);
|
void onUpdateFinished(const QVariantMap &data);
|
||||||
|
void activePlayersChanged(const QVariantList &data);
|
||||||
|
void playerPropertiesReceived(const QVariantMap &properties);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KODI_H
|
#endif // KODI_H
|
||||||
|
|||||||
@ -51,17 +51,17 @@ void KodiJsonHandler::sendData(const QString &method, const QVariantMap ¶ms,
|
|||||||
|
|
||||||
void KodiJsonHandler::processNotification(const QString &method, const QVariantMap ¶ms)
|
void KodiJsonHandler::processNotification(const QString &method, const QVariantMap ¶ms)
|
||||||
{
|
{
|
||||||
//qCDebug(dcKodi) << "got notification" << method;
|
qCDebug(dcKodi) << "got notification" << method;
|
||||||
|
|
||||||
if (method == "Application.OnVolumeChanged") {
|
if (method == "Application.OnVolumeChanged") {
|
||||||
QVariantMap data = params.value("data").toMap();
|
QVariantMap data = params.value("data").toMap();
|
||||||
emit volumeChanged(data.value("volume").toInt(), data.value("muted").toBool());
|
emit volumeChanged(data.value("volume").toInt(), data.value("muted").toBool());
|
||||||
} else if (method == "Player.OnPlay") {
|
} else if (method == "Player.OnPlay") {
|
||||||
emit onPlayerPlay();
|
emit playbackStatusChanged("PLAYING");
|
||||||
} else if (method == "Player.OnPause") {
|
} else if (method == "Player.OnPause") {
|
||||||
emit onPlayerPause();
|
emit playbackStatusChanged("PAUSED");
|
||||||
} else if (method == "Player.OnStop") {
|
} else if (method == "Player.OnStop") {
|
||||||
emit onPlayerStop();
|
emit playbackStatusChanged("STOPPED");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,17 +81,34 @@ void KodiJsonHandler::processRequestResponse(const KodiReply &reply, const QVari
|
|||||||
if (response.contains("error")) {
|
if (response.contains("error")) {
|
||||||
//qCDebug(dcKodi) << QJsonDocument::fromVariant(response).toJson();
|
//qCDebug(dcKodi) << QJsonDocument::fromVariant(response).toJson();
|
||||||
qCWarning(dcKodi) << "got error response for request " << reply.method() << ":" << response.value("error").toMap().value("message").toString();
|
qCWarning(dcKodi) << "got error response for request " << reply.method() << ":" << response.value("error").toMap().value("message").toString();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reply.method() == "Application.GetProperties") {
|
if (reply.method() == "Application.GetProperties") {
|
||||||
//qCDebug(dcKodi) << "got update response" << reply.method();
|
//qCDebug(dcKodi) << "got update response" << reply.method();
|
||||||
emit updateDataReceived(response.value("result").toMap());
|
emit updateDataReceived(response.value("result").toMap());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reply.method() == "JSONRPC.Version") {
|
if (reply.method() == "JSONRPC.Version") {
|
||||||
qCDebug(dcKodi) << "got version response" << reply.method();
|
qCDebug(dcKodi) << "got version response" << reply.method();
|
||||||
emit versionDataReceived(response.value("result").toMap());
|
emit versionDataReceived(response.value("result").toMap());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (reply.method() == "Player.GetActivePlayers") {
|
||||||
|
qCDebug(dcKodi) << "Active players changed" << response;
|
||||||
|
emit activePlayersChanged(response.value("result").toList());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reply.method() == "Player.GetProperties") {
|
||||||
|
qCDebug(dcKodi) << "Player properties received" << response;
|
||||||
|
emit playerPropertiesReveived(response.value("result").toMap());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
qCDebug(dcKodi()) << "unhandled reply" << reply.method() << response;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KodiJsonHandler::processResponse(const QByteArray &data)
|
void KodiJsonHandler::processResponse(const QByteArray &data)
|
||||||
|
|||||||
@ -53,10 +53,10 @@ signals:
|
|||||||
void actionExecuted(const ActionId &actionId, const bool &success);
|
void actionExecuted(const ActionId &actionId, const bool &success);
|
||||||
void updateDataReceived(const QVariantMap &data);
|
void updateDataReceived(const QVariantMap &data);
|
||||||
void versionDataReceived(const QVariantMap &data);
|
void versionDataReceived(const QVariantMap &data);
|
||||||
|
void activePlayersChanged(const QVariantList &data);
|
||||||
|
void playerPropertiesReveived(const QVariantMap &properties);
|
||||||
|
|
||||||
void onPlayerPlay();
|
void playbackStatusChanged(const QString &playbackStatus);
|
||||||
void onPlayerPause();
|
|
||||||
void onPlayerStop();
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void processResponse(const QByteArray &data);
|
void processResponse(const QByteArray &data);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user