gpt4 book ai didi

c++ - 带有 Kodi (XBMC) 的 JSON RPC 以重新启动播放列表中的第一项

转载 作者:行者123 更新时间:2023-11-28 06:29:30 24 4
gpt4 key购买 nike

我正在使用 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

我最好只运行浏览到 http://myKodiMachine.xy:8080/jsonrpc 时得到的 json 文件通过 jsonrpcstub,但这已经创建了语法错误。好像他的文件是这样开头的:

{
"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 文件中,它将起作用:)。

关于c++ - 带有 Kodi (XBMC) 的 JSON RPC 以重新启动播放列表中的第一项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27866324/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com