mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
XBMC video checker added
This commit is contained in:
29
libsrc/xbmcvideochecker/CMakeLists.txt
Normal file
29
libsrc/xbmcvideochecker/CMakeLists.txt
Normal file
@@ -0,0 +1,29 @@
|
||||
|
||||
# Define the current source locations
|
||||
SET(CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include/xbmcvideochecker)
|
||||
SET(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/xbmcvideochecker)
|
||||
|
||||
# Group the headers that go through the MOC compiler
|
||||
SET(XBMCVideoChecker_QT_HEADERS
|
||||
${CURRENT_HEADER_DIR}/XBMCVideoChecker.h
|
||||
)
|
||||
|
||||
SET(XBMCVideoChecker_HEADERS
|
||||
)
|
||||
|
||||
SET(XBMCVideoChecker_SOURCES
|
||||
${CURRENT_SOURCE_DIR}/XBMCVideoChecker.cpp
|
||||
)
|
||||
|
||||
QT4_WRAP_CPP(XBMCVideoChecker_HEADERS_MOC ${XBMCVideoChecker_QT_HEADERS})
|
||||
|
||||
add_library(xbmcvideochecker
|
||||
${XBMCVideoChecker_HEADERS}
|
||||
${XBMCVideoChecker_QT_HEADERS}
|
||||
${XBMCVideoChecker_HEADERS_MOC}
|
||||
${XBMCVideoChecker_SOURCES}
|
||||
)
|
||||
|
||||
target_link_libraries(xbmcvideochecker
|
||||
hyperion
|
||||
${QT_LIBRARIES})
|
59
libsrc/xbmcvideochecker/XBMCVideoChecker.cpp
Normal file
59
libsrc/xbmcvideochecker/XBMCVideoChecker.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
// Qt includes
|
||||
#include <QUrl>
|
||||
|
||||
#include <xbmcvideochecker/XBMCVideoChecker.h>
|
||||
|
||||
XBMCVideoChecker::XBMCVideoChecker(QString address, uint64_t interval_ms, Hyperion * hyperion, int priority) :
|
||||
QObject(),
|
||||
_timer(),
|
||||
_networkManager(),
|
||||
_request(QUrl(QString("http://%1/jsonrpc?request={\"jsonrpc\":\"2.0\",\"method\":\"Player.GetActivePlayers\",\"id\":1}").arg(address))),
|
||||
_hyperion(hyperion),
|
||||
_priority(priority)
|
||||
{
|
||||
// setup timer
|
||||
_timer.setSingleShot(false);
|
||||
_timer.setInterval(interval_ms);
|
||||
connect(&_timer, SIGNAL(timeout()), this, SLOT(sendRequest()));
|
||||
|
||||
//setup network manager
|
||||
connect(&_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(receiveReply(QNetworkReply*)));
|
||||
}
|
||||
|
||||
void XBMCVideoChecker::start()
|
||||
{
|
||||
_timer.start();
|
||||
}
|
||||
|
||||
void XBMCVideoChecker::sendRequest()
|
||||
{
|
||||
_networkManager.get(_request);
|
||||
}
|
||||
|
||||
void XBMCVideoChecker::receiveReply(QNetworkReply * reply)
|
||||
{
|
||||
if (reply->error() != QNetworkReply::NoError)
|
||||
{
|
||||
std::cerr << "Error while requesting XBMC video info: " << reply->errorString().toStdString() << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
const QString jsonReply(reply->readAll());
|
||||
if (jsonReply.contains("playerid"))
|
||||
{
|
||||
// something is playing. check for "video" to check if a video is playing
|
||||
// clear our priority channel to allow the grabbed vido colors to be shown
|
||||
_hyperion->clear(_priority);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Nothing is playing. set our priority channel completely to black
|
||||
// The timeout is used to have the channel cleared after 30 seconds of connection problems...
|
||||
_hyperion->setColor(_priority, RgbColor::BLACK, 30000);
|
||||
}
|
||||
}
|
||||
|
||||
// close reply
|
||||
reply->close();
|
||||
}
|
||||
|
Reference in New Issue
Block a user