Kodi Community Forum

Full Version: Changing audio settings via JSON-RPC
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all,

I read in this thread thats its possible to change audio outputs via json-rpc and I have been able to do so with the following command:

Code:
curl -v -H "Content-type: application/json" -X POST -d '{"jsonrpc":"2.0","method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.audiodevice","value":"ALSA:hdmi:CARD=NVidia,DEV=1"},"id":1}' http://localhost:9191/jsonrpc

However, trying something similar with audiooutput.channels or audiooutput.passthrough (options I found here) I get errors and there is no change in xbmc.

Code:
$ curl -v -H "Content-type: application/json" -X POST -d '{"jsonrpc":"2.0","method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.channels","value":"3"},"id":1}' http://localhost:9191/jsonrpc                           * Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 9191 (#0)
> POST /jsonrpc HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:9191
> Accept: */*
> Content-type: application/json
> Content-Length: 117
>
* upload completely sent off: 117 out of 117 bytes
< HTTP/1.1 200 OK
< Content-Length: 76
< Content-Type: application/json
< Date: Thu, 17 Apr 2014 09:28:09 GMT
<
* Connection #0 to host localhost left intact
{"error":{"code":-32602,"message":"Invalid params."},"id":1,"jsonrpc":"2.0"}xbmc","method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.channels","value":"3"},"id":1}' http://localhost:9191/jsonrpc                           * Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 9191 (#0)
> POST /jsonrpc HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:9191
> Accept: */*
> Content-type: application/json
> Content-Length: 117
>
* upload completely sent off: 117 out of 117 bytes
< HTTP/1.1 200 OK
< Content-Length: 76
< Content-Type: application/json
< Date: Thu, 17 Apr 2014 09:32:01 GMT
<
* Connection #0 to host localhost left intact
{"error":{"code":-32602,"message":"Invalid params."},"id":1,"jsonrpc":"2.0"}

Debug log of this error. Ive tried a whole lot of variations with no success. So Im curious if its possible to change other audio settings via json-rpc, and if so, can anyone point me in the direction of the correct syntax to use?

Thanks in advance.
Well "audiooutput.channels" is an integer setting and "3" is not a valid integer value but a string value. So you need to provide the value as an integer. And audiooutput.passthrough is a boolean setting so you need to provide a boolean value (true/false).
Any chance you can provide a working example? I tried various combinations, I tried using integers for channels and true/false for passthroigh but I didn't get anywhere, I'm not overly familiar with jsonrpc and the syntax's that are required.

Pretty pretty please Big Grin
the list of all settings with their id, types, default values, etc. etc.. -> http://pastebin.com/RVvBjrfp

enjoy!

P.S. some settings may vary and can depend from the platform where XBMC is running. The above comes from a linux box.
Thanks for the link joethefox, that will make it easier to see what options can be changed. Unfortunately Im not getting anywhere with putting the json-rpc command together. Ive disabled json compact output, but I cant work out whats wrong.

Code:
$curl -v -H "Content-type: application/json" -X POST -d '{"jsonrpc":"2.0","method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.passthrough","value":"true","type":"boolean"},"id":1}' http://localhost:9191/jsonrpc
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 9191 (#0)
> POST /jsonrpc HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:9191
> Accept: */*
> Content-type: application/json
> Content-Length: 140
>
* upload completely sent off: 140 out of 140 bytes
< HTTP/1.1 200 OK
< Content-Length: 327
< Content-Type: application/json
< Date: Fri, 18 Apr 2014 11:20:45 GMT
<
{
        "error": {
                "code": -32602,
                "data": {
                        "message": "Too many parameters",
                        "method": "Settings.SetSettingValue",
                        "stack": {
                                "name": "value",
                                "type": [
                                        "string",
                                        "number",
                                        "integer",
                                        "boolean",
                                        "array"
                                ]
                        }
                },
                "message": "Invalid params."
        },
        "id": 1,
        "jsonrpc": "2.0"
}
* Connection #0 to host localhost left intact
Code:
$ curl -v -H "Content-type: application/json" -X POST -d '{"jsonrpc":"2.0","method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.passthrough","value":"true"},"id":1}' http://localhost:9191/jsonrpc
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 9191 (#0)
> POST /jsonrpc HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:9191
> Accept: */*
> Content-type: application/json
> Content-Length: 123
>
* upload completely sent off: 123 out of 123 bytes
< HTTP/1.1 200 OK
< Content-Length: 97
< Content-Type: application/json
< Date: Fri, 18 Apr 2014 11:20:52 GMT
<
{
        "error": {
                "code": -32602,
                "message": "Invalid params."
        },
        "id": 1,
        "jsonrpc": "2.0"
}
* Connection #0 to host localhost left intact
Please first take some time to learn the JSON notation.
Code:
"true"
is not a valid boolean value in JSON, it must be
Code:
true
The same applies to your previous example where you tried to use "3" instead just 3.

So you're request should be
Code:
{"jsonrpc":"2.0","method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.passthrough","value":true},"id":1}
DOH! I missed the lack of quotes on another request I was using as an example Confused

Thanks for your help Montellese, the commands now work Smile