looking for JSON API example... and solution.
#1
Hi all,
I'm trying to have the PC with the database shutdown automatically if it doesn't detect any of its clients are streaming media via XBMC.
Reading this and this shed very little light on a potential solution though I suspect it's doable. Very frustrating. I'm the kind to learn by example and don't find the documentation very helpful in that respect. Thus I need help getting a real life example of what can be done with this API regarding what I'm trying to achieve.
TIA
Reply
#2
It is a bit of a climb to understand the API docs. I recommend you build the foundations and send examples with your player in various states. You can do it with TCP sockets or you can use the HTTP interface, but you will need to send a POST not a GET to http://yourpc/jsonrpc, so you can't just use a browser. That was the method I followed in writing my XBMC driver for CQC.

Specifically I think the following command and example response will tell you if a player is active and which one:

Code:
COMMAND: {"jsonrpc":"2.0","method":"Player.GetActivePlayers","id":1}

RESPONSE: {"id" : 1, "jsonrpc" : "2.0", "result" : { "audio" : false,"picture" : true, "video" : false }}
Reply
#3
(2012-05-05, 15:02)wuench Wrote: It is a bit of a climb to understand the API docs. I recommend you build the foundations and send examples with your player in various states. You can do it with TCP sockets or you can use the HTTP interface, but you will need to send a POST not a GET to http://yourpc/jsonrpc, so you can't just use a browser. That was the method I followed in writing my XBMC driver for CQC.

Specifically I think the following command and example response will tell you if a player is active and which one:

Code:
COMMAND: {"jsonrpc":"2.0","method":"Player.GetActivePlayers","id":1}

RESPONSE: {"id" : 1, "jsonrpc" : "2.0", "result" : { "audio" : false,"picture" : true, "video" : false }}
Sorry to be such a noob but what do I do with that using curl for example if i want to query IP 192.168.0.50?
This is what I tried :
Code:
~$ curl --data-binary '{ "jsonrpc": "2.0", "method": "GetActivePlayers", "id":1}' -H 'content-type: application/json;' http://192.168.0.50:9000/jsonrpc

<html>
    <head>
    <title>Access denied</title>
    </head>
    <body>
    <br/><br/>
    <font color="#0000FF">Error 401 Unauthorized: You need to provide a valid username and password.</font>
    </body>
</html>
A bit of a shot in the dark I know. I'm surprised at the error though since XWMM connects fine to the IP. I left xbmc as user without a password on the settings page.
Reply
#4
I haven't tried it with curl. But the syntax looks right to me. Are you sure 9000 is the correct port, the default web server port is usually 8080. I think 9000 is for TCP socket connections.
Reply
#5
(2012-05-05, 19:11)wuench Wrote: I haven't tried it with curl. But the syntax looks right to me. Are you sure 9000 is the correct port, the default web server port is usually 8080. I think 9000 is for TCP socket connections.
You're right, I got the port wrong. I changed it to 8085. So this is what I get now:
Code:
{"error":{"code":-32601,"message":"Method not found."},"id":1,"jsonrpc":"2.0"}
So I guess "GetActivePlayers" in not the right method... It's "Player.GetActivePlayers". Now I get this:
Code:
{"result":[{"playerid":1,"type":"video"}]}
Making progress...

Reply
#6
Yep that's right. Sorry I forgot that command's response changed with Eden, the example I posted was from Dharma.
Reply

Logout Mark Read Team Forum Stats Members Help
looking for JSON API example... and solution.0