我正在使用libjson(https://github.com/cinemast/libjson-rpc-cpp)和kodi的api(以前称为XBMC来播放/暂停并停止我的Kodi机器。但是,在我停止它之后,我无法再次使用play / pause重新启动它。我使用的方法是:
制作一个jsonrpcstub可以处理的json文件,用于播放/暂停,如下所示:
[
{
"name" : "Player.PlayPause",
"description": "Pauses or unpause playback and returns the new state",
"params": [
{
"$ref": "Player.Id",
"name": "playerid",
"required": true
},
{
"$ref": "Global.Toggle",
"default": "toggle",
"name": "play"
}
],
"returns": {
"$ref": "Player.Speed"
},
"type": "method"
}
]
然后我使用:
#include "xbmcremoteclient.h"
#include <jsonrpccpp/client/connectors/httpclient.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#ifndef WIN32
#include <termios.h>
#else
#include <conio.h>
#endif
#include <unistd.h>
#include <time.h>
#include <iostream>
using namespace jsonrpc;
using namespace std;
int main(int argc, char** argv) {
try {
HttpClient httpclient("http://user:[email protected]:8080/jsonrpc");
XbmcRemoteClient stub(httpclient);
stub.Player_PlayPause(0);
}
catch(JsonRpcException& e) {
cerr << e.what() << endl;
}
return 0;
}
制作一个简单的可执行文件来运行此命令。
但是,当我尝试实现goTo函数时,该方法有效:http://kodi.wiki/view/JSON-RPC_API/v6#Player.GoTo
我无法处理。我一直在更改json文件:
[
{"jsonrpc": "2.0", "method": "Player.PlayPause", "params": { "playerid": 0 }, "id": 1},
{
"name": "Player.GoTo":,
"params": [
{
"name": "playerid",
"required": true
},
{
"name": "to",
"required": true,
"type": [
{
"enums": [
"previous",
"next"
],
"type": "string"
},
{
"description": "position in playlist"
}
]
}
],
"returns": {
"type": "string"
}
}
]
但是尝试通过jsonrpcstub运行它时,我总是收到语法错误:
Exception -32700 : JSON_PARSE_ERROR: The JSON-Object is not JSON-Valid: specification file contains syntax errors
最好是我只运行通过jsonrpcstub浏览到http://myKodiMachine.xy:8080/jsonrpc时获得的json文件,但这已经产生了语法错误。看来他的文件是这样开始的:
{
"description": "JSON-RPC API of XBMC",
"id": "http://xbmc.org/jsonrpc/ServiceDescription.json",
"methods": {
"Addons.ExecuteAddon": {
"description": "Executes the given addon with the given parameters (if possible)",
"params": [
{
"name": "addonid",
"required": true,
"type": "string"
},
{
"default": "",
"name": "params",
"type": [
{
"additionalProperties": {
"default": "",
"type": "string"
},
"type": "object"
},
{
"items": {
"type": "string"
},
"type": "array"
},
{
"description": "URL path (must start with / or ?",
"type": "string"
}
]
},
{
"default": false,
"name": "wait",
"type": "boolean"
}
],
"returns": {
"type": "string"
},
"type": "method"
},
"Addons.GetAddonDetails": {
"description": "Gets the details of a specific addon",
"params": [
{
"name": "addonid",
"required": true,
"type": "string"
},
{
"$ref": "Addon.Fields",
由于某些奇怪的原因,它不是有效的JSON。任何能够从Linux停止和重新启动kodi中的播放列表的指针(如这种方式或任何其他方式)都将被认为是有帮助的。我特别需要这个,因为我播放了很多流,并且如果我暂停它们,它们将被缓冲(这不是很方便),所以我更喜欢停止/重新启动它们。
最佳答案
Kodi提供的json代码对于jsonrpc c ++库几乎没有用,但我还是不太满意,但是我设法使其正常工作,json文件将需要以下行:
{"jsonrpc": "2.0", "method": "Input.ExecuteAction", "params": { "action": "play"}, "id": 1}
然后执行:
stub.Input_ExecuteAction("play");
在cpp文件中,它将起作用:)。