2013-03-01, 21:23
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
Returns
This is just simply a return of the current playlists created and used, as PlaylistID and Type.
--
Files.GetDirectory
Return Example
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.
This plays a slideshow containing all the images in the "Images" directory. The slash may or may not be required. But this works.
This plays the video "Big_Buck_Bunny_1080p.mov" from the Media folder found on the Pi.
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
--
Playlist.Clear
Returns
This clears a playlist you create. This is identified by playlistid in params. Pretty simple.
--
Playlist.Add
Returns
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.
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.