Hey guys,
I've been trying to add some new functionality to a project I'm working on (written in PHP5) and after days of reading everything I could find about sending JSON commands I finally had a eureka moment yesterday and can now send/recieve commands via the new WebSocket. The problems I'm having is although I'm able to make it work now and even after reading results from JSONRPC.Introspect I still can't seem to get a bunch of what I would consider 'simple' things to work.
For now, I'm more interested in creating simple buttons that allow you to toggle stuff like Subtitles on/off or "Scan/Update Library" instead of of doing things like listing movies/shows or whatever. Essentially until I'm able to learn this stuff better, I don't care what the response back is since I'm not formatting any of it (in fact, all the Sent/Response stuff will be hidden from the end user anyway).
While testing I tried adding the settings to the advancedsettings.xml to turn off the compact response so I could use it to learn but it made it so that every second or third command would essentially just kill the browser (not crash, but just sit there and not do anything at all).
I guess I'm wondering if anyone knows of a spot where I can read 'real-world' examples of fully written JSON commands. For example, I'm able to scan the video library with: (which works)
Code:
Send:
{"jsonrpc": "2.0", "method": "VideoLibrary.Scan"}
Response:
{"jsonrpc":"2.0","method":"VideoLibrary.OnScanFinished","params":{"data":null,"sender":"xbmc"}}
but trying to scan the audio library, I've tried each of the following: (no error, but doesn't seem to update the library in XBMC)
Code:
Send:
{"jsonrpc": "2.0", "method": "AudioLibrary.Scan"}
Response:
{"jsonrpc":"2.0","method":"AudioLibrary.OnScanFinished","params":{"data":null,"sender":"xbmc"}}
I also tried the following for AudioLibrary: (again, no error, but doesn't seem to actually do anything)
Code:
Send:
{"jsonrpc": "2.0", "method": "AudioLibrary.Scan", "permissions": "UpdateData"}
Response:
{"jsonrpc":"2.0","method":"AudioLibrary.OnScanFinished","params":{"data":null,"sender":"xbmc"}}
I also tried something else, can't remember the exact command but it led me to believe for Audio you have to specify a directory to scan, which if possible I want to avoid and have it scan the entire thing since the end users will obviously have their media in different locations.
Test Environment:
XBMC Nightly: May 28, 2012
Windows 7 Ultimate x64
I have at least one tester on Linux (I believe Ubuntu) to verify the code works for them as well.
I'm not sure what parts of the project code would be helpful with this, but I'm essentially creating arrays like so:
Code:
<?php
$SubtitleOn = array('{"jsonrpc": "2.0", "method": "Player.SetSubtitle", "params": {"playerid": 1, "subtitle" : "on"}, "id": "1"}');
$SubtitleOff = array('{"jsonrpc": "2.0", "method": "Player.SetSubtitle", "params": {"playerid": 1, "subtitle" : "off"}, "id": "1"}');
$ScanVidLib = array('{"jsonrpc": "2.0", "method": "VideoLibrary.Scan"}');
$VidClean = array('{"jsonrpc": "2.0", "method": "VideoLibrary.Clean", "permissions": "RemoveData", "id": "1"}');
// Currently Broken JSON Commands
$VolMute = array('{"jsonrpc": "2.0", "method": "Application.SetMute", "permissions": "ControlPlayback", "id": "1"}');
$VolUp = array();
$VolDown = array();
$VolMax = array('{"jsonrpc": "2.0", "method": "XBMC.SetVolume", "params": {"SetVolume": 100}, "id": "1"}');
$ScanAudLib = array('{"jsonrpc": "2.0", "method": "AudioLibrary.Scan", "permissions": "UpdateData"}');
?>
And sending them like this:
Code:
<div id="commands"><strong>Video Library</strong>
<button class='classpanel' name='VidScan' onClick='doSend(<?php echo json_encode($ScanVidLib); ?>)'>Scan</button>
<button class='classpanel' name='VidClean' onClick='doSend(<?php echo json_encode($VidClean); ?>)'>Clean</button>
</div>
Before this post gets too much longer, clicking a 'broken' command from above (Example: VolMax) displays the Sent/Response like this:
Code:
SENT: {"jsonrpc": "2.0", "method": "XBMC.SetVolume", "params": {"SetVolume": 100}, "id": "1"}
RESPONSE: {"error":{"code":-32601,"message":"Method not found."},"id":"1","jsonrpc":"2.0"}
Any help would be greatly appreciated. (This project is available on GitHub if seeing the actual code might help you guys...)