Kodi initial fix (#171)

* fix #158

* fix initial state of playbackstate
This commit is contained in:
redPanther 2016-08-13 10:05:11 +02:00 committed by GitHub
parent 7ee2e7cf8d
commit 9c27db390d
2 changed files with 22 additions and 9 deletions

View File

@ -166,5 +166,8 @@ private:
/// flag indicating state /// flag indicating state
bool _active; bool _active;
/// flag indicates if playbackState is valid
bool _getCurrentPlaybackStateInitialized;
static KODIVideoChecker* _kodichecker; static KODIVideoChecker* _kodichecker;
}; };

View File

@ -65,6 +65,7 @@ KODIVideoChecker::KODIVideoChecker(const QString & address, uint16_t port, bool
, _kodiVersion(0) , _kodiVersion(0)
, _log(Logger::getInstance("KODI")) , _log(Logger::getInstance("KODI"))
, _active(false) , _active(false)
, _getCurrentPlaybackStateInitialized(false)
{ {
// setup socket // setup socket
connect(&_socket, SIGNAL(readyRead()), this, SLOT(receiveReply())); connect(&_socket, SIGNAL(readyRead()), this, SLOT(receiveReply()));
@ -143,6 +144,7 @@ void KODIVideoChecker::receiveReply()
// Reply // Reply
if (doc.object().contains("id")) if (doc.object().contains("id"))
{ {
int id = doc.object()["id"].toInt(); int id = doc.object()["id"].toInt();
switch (id) switch (id)
{ {
@ -158,15 +160,18 @@ void KODIVideoChecker::receiveReply()
emit videoMode(VIDEO_2D); emit videoMode(VIDEO_2D);
QString type = resultArray[0].toObject()["type"].toString(); QString type = resultArray[0].toObject()["type"].toString();
int prevCurrentPlayerID = _currentPlayerID; int prevCurrentPlayerID = _currentPlayerID;
_currentPlayerID = resultArray[0].toObject()["playerid"].toInt(); _currentPlayerID = resultArray[0].toObject()["playerid"].toInt();
// set initial player state // set initial player state
if (prevCurrentPlayerID == 0 && _currentPlayerID != 0) if (! _getCurrentPlaybackStateInitialized && prevCurrentPlayerID == 0 && _currentPlayerID != 0)
{ {
_socket.write(_getCurrentPlaybackState.arg(_currentPlayerID).toUtf8()); _socket.write(_getCurrentPlaybackState.arg(_currentPlayerID).toUtf8());
_getCurrentPlaybackStateInitialized = true;
return; return;
} }
if (type == "video") if (type == "video")
{ {
if (_currentPlaybackState) if (_currentPlaybackState)
@ -209,8 +214,10 @@ void KODIVideoChecker::receiveReply()
} }
} }
else else
{
// Nothing is playing. // Nothing is playing.
setGrabbingMode(_grabMenu ? GRABBINGMODE_MENU : GRABBINGMODE_OFF); setGrabbingMode(_grabMenu ? GRABBINGMODE_MENU : GRABBINGMODE_OFF);
}
} }
else else
{ {
@ -229,7 +236,6 @@ void KODIVideoChecker::receiveReply()
{ {
if (doc.object()["result"].toObject()["item"].toObject().contains("file")) if (doc.object()["result"].toObject()["item"].toObject().contains("file"))
{ {
QString filename = doc.object()["result"].toObject()["item"].toObject()["file"].toString(); QString filename = doc.object()["result"].toObject()["item"].toObject()["file"].toString();
if (filename.contains("3DSBS", Qt::CaseInsensitive) || filename.contains("HSBS", Qt::CaseInsensitive)) if (filename.contains("3DSBS", Qt::CaseInsensitive) || filename.contains("HSBS", Qt::CaseInsensitive))
setVideoMode(VIDEO_3DSBS); setVideoMode(VIDEO_3DSBS);
@ -315,7 +321,6 @@ void KODIVideoChecker::receiveReply()
} }
} }
} }
// Notification // Notification
else if (doc.object().contains("method")) else if (doc.object().contains("method"))
{ {
@ -323,8 +328,10 @@ void KODIVideoChecker::receiveReply()
if (method == "Player.OnPlay") if (method == "Player.OnPlay")
{ {
if (doc.object()["params"].toObject()["data"].toObject()["player"].toObject().contains("speed")) if (doc.object()["params"].toObject()["data"].toObject()["player"].toObject().contains("speed"))
{
_getCurrentPlaybackStateInitialized = true;
_currentPlaybackState = static_cast<bool>(doc.object()["params"].toObject()["data"].toObject()["player"].toObject()["speed"].toInt()); _currentPlaybackState = static_cast<bool>(doc.object()["params"].toObject()["data"].toObject()["player"].toObject()["speed"].toInt());
}
// send a request for the current player state // send a request for the current player state
_socket.write(_activePlayerRequest.toUtf8()); _socket.write(_activePlayerRequest.toUtf8());
return; return;
@ -338,8 +345,10 @@ void KODIVideoChecker::receiveReply()
else if (method == "Player.OnPause") else if (method == "Player.OnPause")
{ {
if (doc.object()["params"].toObject()["data"].toObject()["player"].toObject().contains("speed")) if (doc.object()["params"].toObject()["data"].toObject()["player"].toObject().contains("speed"))
{
_getCurrentPlaybackStateInitialized = true;
_currentPlaybackState = static_cast<bool>(doc.object()["params"].toObject()["data"].toObject()["player"].toObject()["speed"].toInt()); _currentPlaybackState = static_cast<bool>(doc.object()["params"].toObject()["data"].toObject()["player"].toObject()["speed"].toInt());
}
// player at pause // player at pause
setGrabbingMode(_grabPause ? GRABBINGMODE_PAUSE : GRABBINGMODE_OFF); setGrabbingMode(_grabPause ? GRABBINGMODE_PAUSE : GRABBINGMODE_OFF);
} }
@ -355,7 +364,6 @@ void KODIVideoChecker::receiveReply()
{ {
// picture viewer is playing // picture viewer is playing
setGrabbingMode(_grabPhoto ? GRABBINGMODE_PHOTO : GRABBINGMODE_OFF); setGrabbingMode(_grabPhoto ? GRABBINGMODE_PHOTO : GRABBINGMODE_OFF);
return;
} }
else if (method == "Input.OnInputFinished") else if (method == "Input.OnInputFinished")
{ {
@ -368,14 +376,16 @@ void KODIVideoChecker::receiveReply()
} }
} }
else else
{
Debug(_log, "Incomplete data"); Debug(_log, "Incomplete data");
}
} }
} }
void KODIVideoChecker::connected() void KODIVideoChecker::connected()
{ {
Info(_log, "Connected"); Info(_log, "Connected");
_getCurrentPlaybackStateInitialized = false;
// send a request for the current player state // send a request for the current player state
_socket.write(_activePlayerRequest.toUtf8()); _socket.write(_activePlayerRequest.toUtf8());
_socket.write(_checkScreensaverRequest.toUtf8()); _socket.write(_checkScreensaverRequest.toUtf8());