mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 22:26:32 +02:00
Add remote controlling of playback
This commit is contained in:
@@ -20,6 +20,13 @@
|
|||||||
|
|
||||||
#include "Api_v1.h"
|
#include "Api_v1.h"
|
||||||
|
|
||||||
|
#include "audio/AudioEngine.h"
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
|
// Assumptions: QxtWebRequestEvent instance is called event and result is true on success
|
||||||
|
#define JSON_REPLY( result, message ) jsonReply( event, Q_FUNC_INFO, message, !result )
|
||||||
|
|
||||||
|
|
||||||
Api_v1_5::Api_v1_5( Api_v1* parent )
|
Api_v1_5::Api_v1_5( Api_v1* parent )
|
||||||
: QObject( parent )
|
: QObject( parent )
|
||||||
, m_service( parent )
|
, m_service( parent )
|
||||||
@@ -35,3 +42,58 @@ Api_v1_5::ping( QxtWebRequestEvent* event )
|
|||||||
m_service->postEvent( e );
|
m_service->postEvent( e );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Api_v1_5::playback( QxtWebRequestEvent* event, const QString& command )
|
||||||
|
{
|
||||||
|
if ( command == "next")
|
||||||
|
{
|
||||||
|
JSON_REPLY( QMetaObject::invokeMethod( AudioEngine::instance(), "next", Qt::QueuedConnection ) , "Skipping to the next track failed." );
|
||||||
|
}
|
||||||
|
else if ( command == "previous" )
|
||||||
|
{
|
||||||
|
JSON_REPLY( QMetaObject::invokeMethod( AudioEngine::instance(), "previous", Qt::QueuedConnection ), "Rewinding to the previous track failed." );
|
||||||
|
}
|
||||||
|
else if ( command == "playpause" )
|
||||||
|
{
|
||||||
|
JSON_REPLY( QMetaObject::invokeMethod( AudioEngine::instance(), "playPause", Qt::QueuedConnection ), "Play/Pause failed." );
|
||||||
|
}
|
||||||
|
else if ( command == "play" )
|
||||||
|
{
|
||||||
|
JSON_REPLY( QMetaObject::invokeMethod( AudioEngine::instance(), "play", Qt::QueuedConnection ), "Starting the playback failed." );
|
||||||
|
}
|
||||||
|
else if ( command == "pause" )
|
||||||
|
{
|
||||||
|
JSON_REPLY( QMetaObject::invokeMethod( AudioEngine::instance(), "pause", Qt::QueuedConnection ), "Pausing the current track failed." );
|
||||||
|
}
|
||||||
|
else if ( command == "stop" )
|
||||||
|
{
|
||||||
|
JSON_REPLY( QMetaObject::invokeMethod( AudioEngine::instance(), "stop", Qt::QueuedConnection ), "Stopping the current track failed." );
|
||||||
|
}
|
||||||
|
else if ( command == "lowervolume" )
|
||||||
|
{
|
||||||
|
JSON_REPLY( QMetaObject::invokeMethod( AudioEngine::instance(), "lowerVolume", Qt::QueuedConnection ), "Lowering volume failed." );
|
||||||
|
}
|
||||||
|
else if ( command == "raisevolume" )
|
||||||
|
{
|
||||||
|
JSON_REPLY( QMetaObject::invokeMethod( AudioEngine::instance(), "raiseVolume", Qt::QueuedConnection ), "Raising volume failed." );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_service->sendJsonError( event, "No such playback command." );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Api_v1_5::jsonReply( QxtWebRequestEvent* event, const char* funcInfo, const QString& errorMessage, bool isError )
|
||||||
|
{
|
||||||
|
if ( isError )
|
||||||
|
{
|
||||||
|
tLog( LOGVERBOSE ) << funcInfo << errorMessage;
|
||||||
|
m_service->sendJsonError( event, errorMessage );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_service->sendJsonOk( event );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -40,6 +40,14 @@ public slots:
|
|||||||
*/
|
*/
|
||||||
void ping( QxtWebRequestEvent* event );
|
void ping( QxtWebRequestEvent* event );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Control playback.
|
||||||
|
*/
|
||||||
|
void playback( QxtWebRequestEvent* event, const QString& command );
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void jsonReply( QxtWebRequestEvent* event, const char* funcInfo, const QString& errorMessage, bool isError );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Api_v1* m_service;
|
Api_v1* m_service;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user