Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #5122 from Montellese/jsonrpc_player_select

JSON-RPC: add possibility to specify the player to be used
  • Loading branch information...
commit 75b49d5b7674e42e2a036ef049d9965e690ac689 2 parents 4456916 + 19f9322
@Montellese Montellese authored
View
10 xbmc/cores/playercorefactory/PlayerCoreConfig.h
@@ -81,6 +81,16 @@ friend class CPlayerCoreFactory;
return m_eCore;
}
+ bool PlaysAudio() const
+ {
+ return m_bPlaysAudio;
+ }
+
+ bool PlaysVideo() const
+ {
+ return m_bPlaysVideo;
+ }
+
IPlayer* CreatePlayer(IPlayerCallback& callback) const
{
IPlayer* pPlayer;
View
14 xbmc/cores/playercorefactory/PlayerCoreFactory.cpp
@@ -126,10 +126,16 @@ std::string CPlayerCoreFactory::GetPlayerName(const PLAYERCOREID eCore) const
CPlayerCoreConfig* CPlayerCoreFactory::GetPlayerConfig(const std::string& strCoreName) const
{
+ return GetPlayerConfig(GetPlayerCore(strCoreName));
+}
+
+CPlayerCoreConfig* CPlayerCoreFactory::GetPlayerConfig(const PLAYERCOREID eCore) const
+{
CSingleLock lock(m_section);
- PLAYERCOREID id = GetPlayerCore(strCoreName);
- if (id != EPC_NONE) return m_vecCoreConfigs[id-1];
- else return NULL;
+ if (eCore != EPC_NONE)
+ return m_vecCoreConfigs[eCore - 1];
+ else
+ return NULL;
}
void CPlayerCoreFactory::GetPlayers( VECPLAYERCORES &vecCores ) const
@@ -263,7 +269,7 @@ PLAYERCOREID CPlayerCoreFactory::GetDefaultPlayer( const CFileItem& item ) const
return EPC_NONE;
}
-PLAYERCOREID CPlayerCoreFactory::SelectPlayerDialog(VECPLAYERCORES &vecCores, float posX, float posY) const
+PLAYERCOREID CPlayerCoreFactory::SelectPlayerDialog(const VECPLAYERCORES &vecCores, float posX, float posY) const
{
CContextButtons choices;
if (vecCores.size())
View
3  xbmc/cores/playercorefactory/PlayerCoreFactory.h
@@ -70,6 +70,7 @@ class CPlayerCoreFactory : public ISettingsHandler
PLAYERCOREID GetPlayerCore(const std::string& strCoreName) const;
CPlayerCoreConfig* GetPlayerConfig(const std::string& strCoreName) const;
+ CPlayerCoreConfig* GetPlayerConfig(const PLAYERCOREID eCore) const;
std::string GetPlayerName(const PLAYERCOREID eCore) const;
IPlayer* CreatePlayer(const PLAYERCOREID eCore, IPlayerCallback& callback) const;
@@ -82,7 +83,7 @@ class CPlayerCoreFactory : public ISettingsHandler
PLAYERCOREID GetDefaultPlayer( const CFileItem& item ) const;
- PLAYERCOREID SelectPlayerDialog(VECPLAYERCORES &vecCores, float posX = 0, float posY = 0) const;
+ PLAYERCOREID SelectPlayerDialog(const VECPLAYERCORES &vecCores, float posX = 0, float posY = 0) const;
PLAYERCOREID SelectPlayerDialog(float posX, float posY) const;
void OnPlayerDiscovered(const std::string& id, const std::string& name, EPLAYERCORES core);
View
1  xbmc/interfaces/json-rpc/JSONServiceDescription.cpp
@@ -61,6 +61,7 @@ JsonRpcMethodMap CJSONServiceDescription::m_methodMaps[] = {
// Player
{ "Player.GetActivePlayers", CPlayerOperations::GetActivePlayers },
+ { "Player.GetPlayers", CPlayerOperations::GetPlayers },
{ "Player.GetProperties", CPlayerOperations::GetProperties },
{ "Player.GetItem", CPlayerOperations::GetItem },
View
81 xbmc/interfaces/json-rpc/PlayerOperations.cpp
@@ -43,6 +43,8 @@
#include "pvr/channels/PVRChannel.h"
#include "pvr/channels/PVRChannelGroupsContainer.h"
#include "cores/IPlayer.h"
+#include "cores/playercorefactory/PlayerCoreConfig.h"
+#include "cores/playercorefactory/PlayerCoreFactory.h"
#include "settings/MediaSettings.h"
using namespace JSONRPC;
@@ -79,6 +81,58 @@ JSONRPC_STATUS CPlayerOperations::GetActivePlayers(const std::string &method, IT
return OK;
}
+JSONRPC_STATUS CPlayerOperations::GetPlayers(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
+{
+ std::string media = parameterObject["media"].asString();
+ result = CVariant(CVariant::VariantTypeArray);
+ VECPLAYERCORES players;
+
+ if (media == "all")
+ CPlayerCoreFactory::Get().GetPlayers(players);
+ else
+ {
+ bool video = false;
+ if (media == "video")
+ video = true;
+
+ CPlayerCoreFactory::Get().GetPlayers(players, true, video);
+ }
+
+ for (VECPLAYERCORES::const_iterator itPlayer = players.begin(); itPlayer != players.end(); ++itPlayer)
+ {
+ PLAYERCOREID playerId = *itPlayer;
+ const CPlayerCoreConfig* playerConfig = CPlayerCoreFactory::Get().GetPlayerConfig(playerId);
+ if (playerConfig == NULL)
+ continue;
+
+ CVariant player(CVariant::VariantTypeObject);
+ player["playercoreid"] = static_cast<int>(playerId);
+ player["name"] = playerConfig->GetName();
+
+ switch (playerConfig->GetType())
+ {
+ case EPC_EXTPLAYER:
+ player["type"] = "external";
+ break;
+
+ case EPC_UPNPPLAYER:
+ player["type"] = "remote";
+ break;
+
+ default:
+ player["type"] = "internal";
+ break;
+ }
+
+ player["playsvideo"] = playerConfig->PlaysVideo();
+ player["playsaudio"] = playerConfig->PlaysAudio();
+
+ result.push_back(player);
+ }
+
+ return OK;
+}
+
JSONRPC_STATUS CPlayerOperations::GetProperties(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
{
PlayerType player = GetPlayer(parameterObject["playerid"]);
@@ -461,9 +515,11 @@ JSONRPC_STATUS CPlayerOperations::Rotate(const std::string &method, ITransportLa
JSONRPC_STATUS CPlayerOperations::Open(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
{
- CVariant optionShuffled = parameterObject["options"]["shuffled"];
- CVariant optionRepeat = parameterObject["options"]["repeat"];
- CVariant optionResume = parameterObject["options"]["resume"];
+ CVariant options = parameterObject["options"];
+ CVariant optionShuffled = options["shuffled"];
+ CVariant optionRepeat = options["repeat"];
+ CVariant optionResume = options["resume"];
+ CVariant optionPlayer = options["playercoreid"];
if (parameterObject["item"].isObject() && parameterObject["item"].isMember("playlistid"))
{
@@ -570,6 +626,25 @@ JSONRPC_STATUS CPlayerOperations::Open(const std::string &method, ITransportLaye
}
else
{
+ // Handle the "playerid" option
+ if (!optionPlayer.isNull())
+ {
+ PLAYERCOREID playerId = (PLAYERCOREID)optionPlayer.asInteger();
+ // check if the there's actually a player with the given player ID
+ if (CPlayerCoreFactory::Get().GetPlayerConfig(playerId) == NULL)
+ return InvalidParams;
+
+ // check if the player can handle at least the first item in the list
+ VECPLAYERCORES possiblePlayers;
+ CPlayerCoreFactory::Get().GetPlayers(*list.Get(0).get(), possiblePlayers);
+ VECPLAYERCORES::const_iterator matchingPlayer = std::find(possiblePlayers.begin(), possiblePlayers.end(), playerId);
+ if (matchingPlayer == possiblePlayers.end())
+ return InvalidParams;
+
+ // set the next player to be used
+ g_application.m_eForcedNextPlayer = playerId;
+ }
+
// Handle "shuffled" option
if (optionShuffled.isBoolean())
list.SetProperty("shuffled", optionShuffled);
View
1  xbmc/interfaces/json-rpc/PlayerOperations.h
@@ -43,6 +43,7 @@ namespace JSONRPC
{
public:
static JSONRPC_STATUS GetActivePlayers(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
+ static JSONRPC_STATUS GetPlayers(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSONRPC_STATUS GetProperties(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSONRPC_STATUS GetItem(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
View
24 xbmc/interfaces/json-rpc/schema/methods.json
@@ -152,6 +152,7 @@
},
{ "name": "options", "type": "object", "additionalProperties": false,
"properties": {
+ "playercoreid": { "type": [ "null", { "type": "integer", "minimum": 1, "required": true } ], "default": null },
"shuffled": { "$ref": "Optional.Boolean" },
"repeat": { "type": [ "null", { "$ref": "Player.Repeat", "required": true } ], "default": null },
"resume": { "type": [
@@ -184,6 +185,29 @@
}
}
},
+ "Player.GetPlayers": {
+ "type": "method",
+ "description": "Get a list of available players",
+ "transport": "Response",
+ "permission": "ReadData",
+ "params": [
+ { "name": "media", "type": "string", "enum": [ "all", "video", "audio" ], "default": "all" }
+ ],
+ "returns": {
+ "type": "array",
+ "uniqueItems": true,
+ "items": {
+ "type": "object",
+ "properties": {
+ "playercoreid": { "type": "integer", "minimum": 1, "required": true },
+ "name": { "$ref": "Global.String.NotEmpty", "required": true },
+ "type": { "type": "string", "enum": [ "internal", "external", "remote" ], "required": true },
+ "playsvideo": { "type": "boolean", "required": true },
+ "playsaudio": { "type": "boolean", "required": true }
+ }
+ }
+ }
+ },
"Player.GetProperties": {
"type": "method",
"description": "Retrieves the values of the given properties",
View
2  xbmc/interfaces/json-rpc/schema/version.txt
@@ -1 +1 @@
-6.16.1
+6.17.0
Please sign in to comment.
Something went wrong with that request. Please try again.