【发布时间】:2015-03-08 02:44:20
【问题描述】:
我正在使用 libjson (https://github.com/cinemast/libjson-rpc-cpp) 和 kodi 的 api(以前称为 XBMC 来播放/暂停和停止我的 Kodi 机器。但是,在我停止它之后,我无法再次通过播放/暂停重新启动它。方法我用: 制作一个 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:pass@tombrix.student.utwente.nl: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 中的播放列表(像这样或任何其他方式)的指针都将被认为是有帮助的。我特别需要这个,因为我播放了很多流,如果我暂停它们,它们会被缓冲(这不是很方便),所以我更喜欢停止/重新启动它们。
【问题讨论】:
-
您收到错误是因为
"name": "Player.GoTo":,不是有效的 JSON -
这确实是 json 错误,但我仍然不明白为什么我无法解析 kodi jsonrpc 服务器最初返回给我的所有函数...