• 1(current)
  • 2
  • 3
  • 4
  • 5
  • 16
Working JSON RPC API Examples
#1
While trying to figure out the JSON RPC API I tried to find some examples, and have learned that in the past in other languages that examples are extremely powerful for the learning process. So seeing as there isn't much out there to my knowledge as far as working examples, I figured I would put some on here and hope it helps someone. Maybe if other could contribute we could sticky this and help out newer users of the API.

So here is a few of mine.

Some setup information here, this is setup on a basic wired network, with a Raspberry Pi having an IP Address of 192.168.15.117. There are a few things you have to do to get this working the way that I have done. They require steps 3 and 4 here.

Then these are just pasted into the browser of another computer on the same network for testing purposes.

Playlist.GetPlaylists

Code:
http://192.168.15.117/jsonrpc?request={"jsonrpc": "2.0", "id": 1, "method": "Playlist.GetPlaylists"}

Returns
Code:
{"id":1,"jsonrpc":"2.0","result":[{"playlistid":0,"type":"audio"},{"playlistid":1,"type":"video"},{"playlistid":2,"type":"picture"}]}

This is just simply a return of the current playlists created and used, as PlaylistID and Type.

--

Files.GetDirectory

Code:
http://192.168.15.117/jsonrpc?request={"jsonrpc":"2.0","id":1,"method":"Files.GetDirectory","params":{"directory":"Media","media":"video"}}

Return Example
Code:
{"id":1,"jsonrpc":"2.0","result":{"files":[{"file":"Media/Big_Buck_Bunny_720.strm","filetype":"file","label":"Big_Buck_Bunny_720.strm","type":"unknown"},{"file":"Media/Big_Buck_Bunny_1080p.mov","filetype":"file","label":"Big_Buck_Bunny_1080p.mov","type":"unknown"}],"limits":{"end":2,"start":0,"total":2}}}

Basically just a listing of the media type you requested in the Directory you requested. In the call "Media" is our path, and video is our media type.

--

Player.Open

This one can work a few ways. You can do a slideshow of images from a Directory, file, or play a video from file. I am sure there is more methods for this, but you will have to go read the documentation for further information.
Code:
//Slideshow of Images from a Directory "Images"
http://192.168.15.117/jsonrpc?request={"jsonrpc":"2.0","id":"1","method":"Player.Open","params":{"item":{"directory":"Images/"}}}

This plays a slideshow containing all the images in the "Images" directory. The slash may or may not be required. But this works.

Code:
//Play a single video from file
http://192.168.15.117/jsonrpc?request={"jsonrpc":"2.0","id":"1","method":"Player.Open","params":{"item":{"file":"Media/Big_Buck_Bunny_1080p.mov"}}}

This plays the video "Big_Buck_Bunny_1080p.mov" from the Media folder found on the Pi.

Code:
http://192.168.15.117/jsonrpc?request={"jsonrpc":"2.0","id":1,"method":"Player.Open","params":{"item":{"playlistid":1},"options":{"repeat":"all"}}}

This plays the playlist corresponding to playlistid 1. It also continuously repeats the items at the end of the playlist.

Note: After some discussion, a single file cannot be applied a repeat option. It may accept it but it will not apply it to a single video. Repeating at time of writing requires a Playlist.

Returns
Code:
{"id":1,"jsonrpc":"2.0","result":"OK"}

--

Playlist.Clear

Code:
http://192.168.15.117/jsonrpc?request={"jsonrpc":"2.0","id":1,"method":"Playlist.Clear","params":{"playlistid":1}}

Returns
Code:
{"id":1,"jsonrpc":"2.0","result":"OK"}

This clears a playlist you create. This is identified by playlistid in params. Pretty simple.

--

Playlist.Add

Code:
http://192.168.15.117/jsonrpc?request={"jsonrpc":"2.0","id":1,"method":"Playlist.Add","params":{"playlistid":1,"item":{"file":"Media/Big_Buck_Bunny_1080p.mov"}}}

Returns
Code:
{"id":1,"jsonrpc":"2.0","result":"OK"}

This adds the file to the playlist with the corresponding playlistid. In this case, Big Buck Bunny is being added to playlistid 1. You can repeat this as many times as needed (not sure if there is a limit..?) to create a playlist.

--

These are what I have encountered so far. I know I had some troubles getting this to work at first because there was no example usage. So I hope these can help others in the future to get going on their projects.
Reply
#2
http://wiki.xbmc.org/index.php?title=JSO...I#Examples
Image
Reply
#3
I supposed I could have added mine in there huh?
Reply
#4
Thank you so much!

I have been wasting a lot of time chasing around just to do a super simple task: "open a file", by reading this over and over http://wiki.xbmc.org/index.php?title=JSO...layer.Open & its Obj Json Schema and still dont get a sh!t

Your examples are worth more than that whole doc.
Reply
#5
(2013-03-16, 01:00)ndxtg Wrote: Thank you so much!

I have been wasting a lot of time chasing around just to do a super simple task: "open a file", by reading this over and over http://wiki.xbmc.org/index.php?title=JSO...layer.Open & its Obj Json Schema and still dont get a sh!t

Your examples are worth more than that whole doc.

That is why I put these here. I had the same problem and thought I couldn't be the only one.. Glad I could help.
Reply
#6
Thanks for this. Have you had any joy in opening a .strm file with player.open ? I keep getting a parse error which ever way I try.
Reply
#7
I have had a .strm file working, And if I am not mistaken its just a container. We ditched the actual .strm and went directly to the stream.

I will try and get one for you in the next few days that will work, so you can dissect it and apply it to your application.
Reply
#8
Hi, maybe you can help me out, i want to play a radio stream that is in my favorites(left button corner). I would like to do that with json, have you got any idea how i should do it? The addon for the stream is radio...

Thanks in advance,

Frans
Reply
#9
Thank you for sharing this. It got me over the first hurdle, now I've gotta figure out how to use "VideoLibrary.SetMovieDetails" for tag writing. It's really quite tough to get started on something like this, with lots of 'read the wiki' and RTFM responses to wade through. Examples are key - cheers.
Reply
#10
{"jsonrpc": "2.0", "id": 1, "method": "VideoLibrary.SetMovieDetails", "params": {"movieid" : XBMCMOVIEIDINTEGER, "tag":["YOURTAGHERE"]}}

that's how you get ants. or maybe how to write tags with jsonrpc.
Reply
#11
Don't forget that tags are replaced with new values and not merged.

So to add a tag you need to get the tags and set the old tags + the new one.
Reply
#12
(2013-04-29, 20:19)Tolriq Wrote: Don't forget that tags are replaced with new values and not merged.

So to add a tag you need to get the tags and set the old tags + the new one.

Wow. I had so totally not thought of that - thanks!
Reply
#13
Hi!

I'm using Eventghost for XBMC communication and can't seem to understand the paramter section of the plugin. Do anyone have tips?
I would like to play a movie with the id. If not trought evnetghost, what would the JSON link bee?
Reply
#14
(2013-03-16, 01:06)Pghpunkid Wrote: That is why I put these here. I had the same problem and thought I couldn't be the only one.. Glad I could help.

I had exactly the same experience when working with the JSON-RPC a while back, thank you so much for this thread.
Reply
#15
(2013-05-22, 13:26)storstenson Wrote: I'm using Eventghost for XBMC communication and can't seem to understand the paramter section of the plugin. Do anyone have tips?
I would like to play a movie with the id. If not trought evnetghost, what would the JSON link bee?
I assume you are using my XBMC2 EventGhost plugin? Then to play a movie with a specific id you would use:


XBMC2\Experimental\JSONRPC action, choose Player.Open and {"item":{"movieid":4419}} or [{"movieid":4419}] as the parameter.

I'm working on making the JSON-RPC support easier to use but its going slowly. Confused

To get Frodo and later support you need to use one of the later "Test" versions.

jonib
XBMC2, EventGhost plugin. Image
Reply
  • 1(current)
  • 2
  • 3
  • 4
  • 5
  • 16

Logout Mark Read Team Forum Stats Members Help
Working JSON RPC API Examples0