JSON 与 Kodi (XBMC) 的 RPC 以重新启动播放列表中的第一项
JSON RPC with Kodi (XBMC) to restart first item in playlist
我正在使用 libjson (https://github.com/cinemast/libjson-rpc-cpp) 和 kodi 的 api(以前将 XBMC 称为 play/pause 并停止我的 Kodi 机器。但是,在我停止它,我不能再次用 play/pause 重新启动它。我使用的方法:
制作一个 json 文件,jsonrpcstub 可以处理,对于 play/pause 像这样:
[
{
"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 中的播放列表的指示都将被认为是有帮助的。我特别需要这个,因为我播放了很多流,如果我暂停它们,它们会被缓冲(这不是很方便),所以我更喜欢 stop/restart 它们。
仍然不太满意 kodi 提供的 json 代码对 jsonrpc c++ 库毫无用处,但我设法让它工作,json 文件将需要这一行:
{"jsonrpc": "2.0", "method": "Input.ExecuteAction", "params": { "action": "play"}, "id": 1}
然后做:
stub.Input_ExecuteAction("play");
在 cpp 文件中,它将起作用:)。
我正在使用 libjson (https://github.com/cinemast/libjson-rpc-cpp) 和 kodi 的 api(以前将 XBMC 称为 play/pause 并停止我的 Kodi 机器。但是,在我停止它,我不能再次用 play/pause 重新启动它。我使用的方法: 制作一个 json 文件,jsonrpcstub 可以处理,对于 play/pause 像这样:
[
{
"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 中的播放列表的指示都将被认为是有帮助的。我特别需要这个,因为我播放了很多流,如果我暂停它们,它们会被缓冲(这不是很方便),所以我更喜欢 stop/restart 它们。
仍然不太满意 kodi 提供的 json 代码对 jsonrpc c++ 库毫无用处,但我设法让它工作,json 文件将需要这一行:
{"jsonrpc": "2.0", "method": "Input.ExecuteAction", "params": { "action": "play"}, "id": 1}
然后做:
stub.Input_ExecuteAction("play");
在 cpp 文件中,它将起作用:)。