Skip to content

Commit

Permalink
Merge pull request #1404 from Montellese/jsonrpc_partymode
Browse files Browse the repository at this point in the history
jsonrpc: add support for partymode to Player.Open
  • Loading branch information
Montellese committed Oct 1, 2012
2 parents fee57ef + 95c4719 commit a31cdbd
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 0 deletions.
11 changes: 11 additions & 0 deletions xbmc/PartyModeManager.cpp
Expand Up @@ -550,6 +550,17 @@ int CPartyModeManager::GetRandomSongs()
return m_iRandomSongs;
}

PartyModeContext CPartyModeManager::GetType() const
{
if (!IsEnabled())
return PARTYMODECONTEXT_UNKNOWN;

if (m_bIsVideo)
return PARTYMODECONTEXT_VIDEO;

return PARTYMODECONTEXT_MUSIC;
}

void CPartyModeManager::ClearState()
{
m_iLastUserSong = -1;
Expand Down
1 change: 1 addition & 0 deletions xbmc/PartyModeManager.h
Expand Up @@ -56,6 +56,7 @@ class CPartyModeManager
int GetMatchingSongsLeft();
int GetRelaxedSongs();
int GetRandomSongs();
PartyModeContext GetType() const;

private:
void Process();
Expand Down
1 change: 1 addition & 0 deletions xbmc/interfaces/json-rpc/JSONServiceDescription.cpp
Expand Up @@ -80,6 +80,7 @@ JsonRpcMethodMap CJSONServiceDescription::m_methodMaps[] = {
{ "Player.Shuffle", CPlayerOperations::Shuffle },
{ "Player.UnShuffle", CPlayerOperations::UnShuffle },
{ "Player.Repeat", CPlayerOperations::Repeat },
{ "Player.SetPartymode", CPlayerOperations::SetPartymode },

{ "Player.SetAudioStream", CPlayerOperations::SetAudioStream },
{ "Player.SetSubtitle", CPlayerOperations::SetSubtitle },
Expand Down
59 changes: 59 additions & 0 deletions xbmc/interfaces/json-rpc/PlayerOperations.cpp
Expand Up @@ -34,6 +34,8 @@
#include "video/VideoDatabase.h"
#include "AudioLibrary.h"
#include "GUIInfoManager.h"
#include "filesystem/File.h"
#include "PartyModeManager.h"

using namespace JSONRPC;
using namespace PLAYLIST;
Expand Down Expand Up @@ -495,6 +497,13 @@ JSONRPC_STATUS CPlayerOperations::Open(const CStdString &method, ITransportLayer
(!optionShuffled.isBoolean() && parameterObject["item"]["random"].asBoolean());
return StartSlideshow(parameterObject["item"]["path"].asString(), parameterObject["item"]["recursive"].asBoolean(), random);
}
else if (parameterObject["item"].isObject() && parameterObject["item"].isMember("partymode"))
{
if (g_partyModeManager.IsEnabled())
g_partyModeManager.Disable();
CApplicationMessenger::Get().ExecBuiltIn("playercontrol(partymode(" + parameterObject["item"]["partymode"].asString() + "))");
return ACK;
}
else
{
CFileItemList list;
Expand Down Expand Up @@ -672,6 +681,56 @@ JSONRPC_STATUS CPlayerOperations::Repeat(const CStdString &method, ITransportLay
return ACK;
}

JSONRPC_STATUS CPlayerOperations::SetPartymode(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
{
PlayerType player = GetPlayer(parameterObject["playerid"]);
switch (player)
{
case Video:
case Audio:
{
bool change = false;
PartyModeContext context = PARTYMODECONTEXT_UNKNOWN;
std::string strContext;
if (player == Video)
{
context = PARTYMODECONTEXT_VIDEO;
strContext = "video";
}
else if (player == Audio)
{
context = PARTYMODECONTEXT_MUSIC;
strContext = "music";
}

bool toggle = parameterObject["partymode"].isString();
if (g_partyModeManager.IsEnabled())
{
if (g_partyModeManager.GetType() != context)
return InvalidParams;

if (toggle || parameterObject["partymode"].asBoolean() == false)
change = true;
}
else
{
if (toggle || parameterObject["partymode"].asBoolean() == true)
change = true;
}

if (change)
CApplicationMessenger::Get().ExecBuiltIn("playercontrol(partymode(" + strContext + "))");
break;
}

case Picture:
default:
return FailedToExecute;
}

return ACK;
}

JSONRPC_STATUS CPlayerOperations::SetAudioStream(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
{
switch (GetPlayer(parameterObject["playerid"]))
Expand Down
1 change: 1 addition & 0 deletions xbmc/interfaces/json-rpc/PlayerOperations.h
Expand Up @@ -64,6 +64,7 @@ namespace JSONRPC
static JSONRPC_STATUS Shuffle(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSONRPC_STATUS UnShuffle(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSONRPC_STATUS Repeat(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSONRPC_STATUS SetPartymode(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);

static JSONRPC_STATUS SetAudioStream(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSONRPC_STATUS SetSubtitle(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
Expand Down
20 changes: 20 additions & 0 deletions xbmc/interfaces/json-rpc/ServiceDescription.h
Expand Up @@ -1182,6 +1182,15 @@ namespace JSONRPC
"\"random\": { \"type\": \"boolean\", \"default\": true, \"description\": \"Deprecated, use the shuffled property of the options parameter instead\" },"
"\"recursive\": { \"type\": \"boolean\", \"default\": true }"
"}"
"},"
"{ \"type\": \"object\", \"required\": true, \"additionalProperties\": false,"
"\"properties\": {"
"\"partymode\": { \"type\": ["
"{ \"type\": \"string\", \"required\": true, \"enum\": [ \"music\", \"video\" ] },"
"{ \"type\": \"string\", \"required\": true, \"minLength\": 5, \"description\": \"Path to a smartplaylist (*.xsp) file\" }"
"]"
"}"
"}"
"}"
"]"
"},"
Expand Down Expand Up @@ -1449,6 +1458,17 @@ namespace JSONRPC
"],"
"\"returns\": \"string\""
"}",
"\"Player.SetPartymode\": {"
"\"type\": \"method\","
"\"description\": \"Turn partymode on or off\","
"\"transport\": \"Response\","
"\"permission\": \"ControlPlayback\","
"\"params\": ["
"{ \"name\": \"playerid\", \"$ref\": \"Player.Id\", \"required\": true },"
"{ \"name\": \"partymode\", \"$ref\": \"Global.Toggle\", \"required\": true }"
"],"
"\"returns\": \"string\""
"}",
"\"Player.SetAudioStream\": {"
"\"type\": \"method\","
"\"description\": \"Set the audio stream played by the player\","
Expand Down
20 changes: 20 additions & 0 deletions xbmc/interfaces/json-rpc/methods.json
Expand Up @@ -117,6 +117,15 @@
"random": { "type": "boolean", "default": true, "description": "Deprecated, use the shuffled property of the options parameter instead" },
"recursive": { "type": "boolean", "default": true }
}
},
{ "type": "object", "required": true, "additionalProperties": false,
"properties": {
"partymode": { "type": [
{ "type": "string", "required": true, "enum": [ "music", "video" ] },
{ "type": "string", "required": true, "minLength": 5, "description": "Path to a smartplaylist (*.xsp) file" }
]
}
}
}
]
},
Expand Down Expand Up @@ -384,6 +393,17 @@
],
"returns": "string"
},
"Player.SetPartymode": {
"type": "method",
"description": "Turn partymode on or off",
"transport": "Response",
"permission": "ControlPlayback",
"params": [
{ "name": "playerid", "$ref": "Player.Id", "required": true },
{ "name": "partymode", "$ref": "Global.Toggle", "required": true }
],
"returns": "string"
},
"Player.SetAudioStream": {
"type": "method",
"description": "Set the audio stream played by the player",
Expand Down

0 comments on commit a31cdbd

Please sign in to comment.