Skip to content

Commit

Permalink
jsonrpc: add explicitly named parameters to Player.Seek and support s…
Browse files Browse the repository at this point in the history
…eeking by a number of seconds
  • Loading branch information
Montellese authored and xhaggi committed Mar 26, 2015
1 parent 309aa6f commit 0ce3e89
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
22 changes: 15 additions & 7 deletions xbmc/interfaces/json-rpc/PlayerOperations.cpp
Expand Up @@ -47,6 +47,7 @@
#include "cores/playercorefactory/PlayerCoreConfig.h"
#include "cores/playercorefactory/PlayerCoreFactory.h"
#include "settings/MediaSettings.h"
#include "utils/SeekHandler.h"

using namespace JSONRPC;
using namespace PLAYLIST;
Expand Down Expand Up @@ -392,16 +393,18 @@ JSONRPC_STATUS CPlayerOperations::Seek(const std::string &method, ITransportLaye
{
case Video:
case Audio:
{
if (!g_application.m_pPlayer->CanSeek())
return FailedToExecute;

if (parameterObject["value"].isObject())
g_application.SeekTime(ParseTimeInSeconds(parameterObject["value"]));
else if (IsType(parameterObject["value"], NumberValue))
g_application.SeekPercentage(parameterObject["value"].asFloat());
else if (parameterObject["value"].isString())

const CVariant& value = parameterObject["value"];
if (IsType(value, NumberValue) ||
(value.isObject() && value.isMember("percentage")))
g_application.SeekPercentage(IsType(value, NumberValue) ? value.asFloat() : value["percentage"].asFloat());
else if (value.isString() ||
(value.isObject() && value.isMember("step")))
{
std::string step = parameterObject["value"].asString();
std::string step = value.isString() ? value.asString() : value["step"].asString();
if (step == "smallforward")
CBuiltins::Execute("playercontrol(smallskipforward)");
else if (step == "smallbackward")
Expand All @@ -413,13 +416,18 @@ JSONRPC_STATUS CPlayerOperations::Seek(const std::string &method, ITransportLaye
else
return InvalidParams;
}
else if (value.isObject() && value.isMember("seconds"))
CSeekHandler::Get().SeekSeconds(static_cast<int>(value["seconds"].asInteger()));
else if (value.isObject())
g_application.SeekTime(ParseTimeInSeconds(value.isMember("time") ? value["time"] : value));
else
return InvalidParams;

GetPropertyValue(player, "percentage", result["percentage"]);
GetPropertyValue(player, "time", result["time"]);
GetPropertyValue(player, "totaltime", result["totaltime"]);
return OK;
}

case Picture:
case None:
Expand Down
6 changes: 5 additions & 1 deletion xbmc/interfaces/json-rpc/schema/methods.json
Expand Up @@ -291,7 +291,11 @@
{ "name": "value", "required": true, "type": [
{ "$ref": "Player.Position.Percentage", "required": true, "description": "Percentage value to seek to" },
{ "$ref": "Player.Position.Time", "required": true, "description": "Time to seek to" },
{ "type": "string", "enum": [ "smallforward", "smallbackward", "bigforward", "bigbackward" ], "required": true, "description": "Seek by predefined jumps" }
{ "type": "string", "enum": [ "smallforward", "smallbackward", "bigforward", "bigbackward" ], "required": true, "description": "Seek by predefined jumps" },
{ "type": "object", "properties": { "percentage": { "$ref": "Player.Position.Percentage", "required": true, "description": "Percentage value to seek to" } }, "additionalProperties": false, "required": true },
{ "type": "object", "properties": { "time": { "$ref": "Player.Position.Time", "required": true, "description": "Time to seek to" } }, "additionalProperties": false, "required": true },
{ "type": "object", "properties": { "step": { "type": "string", "enum": [ "smallforward", "smallbackward", "bigforward", "bigbackward" ], "required": true, "description": "Seek by predefined jumps" } }, "additionalProperties": false, "required": true },
{ "type": "object", "properties": { "seconds": { "type": "integer", "required": true, "description": "Seek by the given number of seconds" } }, "additionalProperties": false, "required": true }
]
}
],
Expand Down
2 changes: 1 addition & 1 deletion xbmc/interfaces/json-rpc/schema/version.txt
@@ -1 +1 @@
6.22.2
6.23.0

0 comments on commit 0ce3e89

Please sign in to comment.