Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

jsonrpc: add support for partymode to Player.Open #1404

Merged
merged 2 commits into from Oct 1, 2012
Jump to file or symbol
Failed to load files and symbols.
+113 −0
Split
View
@@ -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;
View
@@ -56,6 +56,7 @@ class CPartyModeManager
int GetMatchingSongsLeft();
int GetRelaxedSongs();
int GetRandomSongs();
+ PartyModeContext GetType() const;
private:
void Process();
@@ -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 },
@@ -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;
@@ -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;
@@ -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"]))
@@ -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);
@@ -1181,6 +1181,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\" }"
+ "]"
+ "}"
+ "}"
"}"
"]"
"},"
@@ -1448,6 +1457,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\","
@@ -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" }
+ ]
+ }
+ }
}
]
},
@@ -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",