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

标签 c++ json json-rpc xbmc

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

相关文章:

javascript - Ember 数据 JSON-RPC 请求示例

c++ - 使用strtok拆分文本而不删除delim c++

c++ - 在 Visual C++ 中读取 WMI 中的 uint 数组属性

ios - 发布路径必须与 RKResponseDescriptor pathPattern 完全匹配

asp.net - ASP.NET 的 JSON 最大长度问题

python - 以干净、分离的方式向简单的 RPC 服务器添加方法

c++ - 将 haskell 解释器(提示)构建为动态库,可从 C++ : Missing Interpreter. dyn_hi 使用

c++ - 具有抽象类类型的函数声明是否格式错误?

javascript - getJSON 返回 null

java - java 上的 Json-rpc 服务用于 jquery 终端模拟器