.Net JSON-RPC Client Generator
#1
Hello,

I would like to announce a new .Net, Silverlight, WinRT and Windows Phone client for the JSON RPC API. It is auto generated from the JSONRPC.Introspect’s result.
Details can be found at Codeplex: JSON-RPC Client Generator (for XBMC)

Regards
Steve


Here the details from the project page:



The generator takes the JSON schema returned by the JSONRPC.Introspect method and generates C# types and methods. The classes should be compatible with .Net, Silverlight, WinRT and Windows Phone. The methods support the async/await feature of Visual Studio 2012.

The advantages of this auto generated .Net API client:
  • Containing ALL methods of the XBMC API
  • No manual maintenance of single methods
  • Uses the same type and method names used in the API documentation
  • Fast availability, if new methods are added to the XBMC API

This first release has been tested on .Net 4.5. I will test the generated code on Windows Phone 7 as soon as the new Windows Phone 8 SDK is released.

If you don’t want to wait and want to use the async/await feature for Windows Phone 7 development, you need the Async CTP for Visual Studio 2010. You should install this on a clean virtual machine because of the problems described in this post.

The generated code references the JSON.Net framework.

To generator code does not implement all aspects of JSON schema. Only the parts necessary to get the XBMC client running are implemented.
Reply
#2
I added a WinRT sample for Windows 8.
It shows the usage of paged data virtualization for fluid UIs and image caching.


BTW:I fixed some bugs in enum handing and added Support for the new filter types in the generator.
Reply
#3
I'm very new to using the JSON interface. I am able to connect to an XBMC Instance and retrieve player status, and information about the currently playing media. However I have run into a couple issues. I cant seem to figure out how to download the thumbnails for the currently playing item. I have tried to use File.PrepareDownload and GetImageStream but I always get errors. I suspect its an authentication issue, since I cant view the image in a browser using the thumbnail path unless I supply a username and password. Which leads me to the next issue, I can't connect to an XBMC instance that does not specify a password. If I create a new Client using

private Client xbmc = new Client("localhost", 8080, "xbmc", "");
or
private Client xbmc = new Client("localhost", 8080, "xbmc", null);

then GetActivePlayers throws a WebException : (401) Unauthorized.
Reply
#4
I added asample that shows your wanted functionality. Here is the relevant code:

Code:
var wellKnownPlayerIdVideo = 1; //or use xbmc.Player.GetActivePlayers()
var getCurrentItemResponse = await xbmc.Player.GetItem(wellKnownPlayerIdVideo, All.AllFields());
var currentPlayingVideo = getCurrentItemResponse.item as AllFile; //use AllMedia for audio player or the shared base class for both: XBMCRPC.Media.Details.Base
var imageStream = await xbmc.GetImageStream(currentPlayingVideo.thumbnail);
            
//display in image control:
var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = imageStream;
bitmapImage.EndInit();
ThumbImage.Source = bitmapImage;

A cannot reproduce you authentication issues. The code works for me with and without authentication. Which version/build of XBMC are you using?

It is a bit confusing: XBMC should not report "(401) Unauthorized", if you do not specify a password. I can acces the images in browser without login, if I don't specify a password.
Reply
#5
I'm using 11.0 stable on Windows 7 64 bit. I'll test your code when I get home. I did come up with a solution on my own that used a WebRequest and specified NetworkCredential to get to work.

I know its a bit confusing, If xbmc is set to not require a password, then I can view the thumbnails in a browser without specifying a username or password. But, then I get an exception from GetActivePlayers.
If xbmc is set to require a password. I can only view thumbnails in a browser by entering a username and password. But then my code works using the WebRequest/NetworkCredential workaround I mentioned above, so that's the solution I'm using for now. I can get code samples later If you want.
Reply
#6
I tried the code on XBMC 11. I had to make a modification to the GetImageStream helper method. It works for me on XBMC 11 and 12 with and without authentication.

If you want to work with XBMC 11 you have to run "JsonRpcGen" again. The sample version on Codeplex has been generated using XBMC 12.
Reply
#7
This looks great, and future proof (hopefully). The main thing that I want to get out this is to be able to receive notifications from XBMC when it starts/stops playing a media file. Is there any kind of event handling with the generated library that would be able to do this?
Reply
#8
At the moment the notifications are not implemented. It would only make sense on a bidirectional transport channel (TCP or WebSockets). At the moment the client uses only HTTP for communication.
Reply
#9
Is there any plan to implement notifications? It is essential for the project I am working on. I want to connect XBMC to my home automation system and want to have the system run logic when XBMC starts playing a video, like dim lights in the room.
Reply
#10
Today, I checked in version with support for notifications. The current client library has been generated using XBMC 12 RC2.

For notifications, you must use the TCP transport on port 9090. The method calls still uses the HTTP transport.

Here is a little sample:

var xbmc = new Client("localhost", 80, "xbmc", "xbmc");
xbmc.Playlist.OnClear += Playlist_OnClear;
xbmc.StartNotificationListener();
Reply
#11
The notifications work great! Now I am trying to figure out how to maintain a connection with an XBMC system if it happens to close and re-open. Would you happen to have any example of how to check if a client has been disconnected and then reconnect? I am not as familiar with all the asynchronous stuff.

Thanks.
Reply
#12
I noticed something when working with the library. When you call StartNotificationListener for a machine that is offline the library will thrown an unhandled exception. This wouldn't be a big problem except that it is asynchronous so there is no way to handle the exception gracefully in my program. It just causes the app to crash.
Reply
#13
You'll probably want to disregard the following, I didn't realise that Visual Studio 2012 was trying to build all the projects when I asked it to build one, and I hadn't fixed the references on all of them because I was only really interested in JsonRpcGen (sorry!).

My original confused message, for posterity:

I'm probably doing something really stupid here, but I'm getting
Quote:'The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)'
even after adding downloading JSON.Net, unzipping it, and adding a reference to the .dll to the project (to replace the one that was already there but not working). Newtonsoft.Json appears okay in the Object Browser, with all the methods and everything. Can anyone guess what stupid thing I'm doing wrong here? I tried copying the relevant .dll file to the /bin directory of the project, and I tried referencing it where it was in the first place; it didn't seem to make any difference either way.
Reply
#14
Since upgrading to XBMC 12.2 this has stopped working. I thought I could just re-generate the library to catch any changes, but I am not able to run the JsonRcpGen app successfully. I get a bunch of runtime errors. Has anyone else been able to generate the library with v12.2?
Reply
#15
I'm seeing problems here too. It looks like it is generating most of the classes, but then doesn't implement all the interfaces, and generates build errors. Any updates ?
KODI:
Windows 10, 32 GB of ram, AMD Phenom X6 @ 2.80 ghz, Using onboard video card with HDMI out
Reply

Logout Mark Read Team Forum Stats Members Help
.Net JSON-RPC Client Generator0