Kodi Community Forum
Help getting player state - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Kodi Application (https://forum.kodi.tv/forumdisplay.php?fid=93)
+---- Forum: JSON-RPC (https://forum.kodi.tv/forumdisplay.php?fid=174)
+---- Thread: Help getting player state (/showthread.php?tid=148181)



Help getting player state - mossywell - 2012-12-13

Wow - and I thought MAPI was tricky. :-p

So, this is the deprecated one-liner for getting the player state:
http://192.168.0.1:8080/xbmcCmds/xbmcHttp?command=getcurrentlyplaying

In JSON RPC, I think that I first have to enumerate all the players. I think. But then what? I can stop, start, pause, but how do I say "what is happening now?"?
What I am finding immensely frustration, is that whilst the methods are published, there's no explanation of why I need to do stuff, so for example I am struggling to see why I need to enumerate players, or even what that means.

So, my question is, am I missing a wiki page that I haven't found?
http://wiki.xbmc.org/index.php?title=JSON-RPC_API/v4
http://forum.xbmc.org/showthread.php?tid=98551

Failing that, how much long will the simpler xbmcCmds be around for?



RE: Help getting player state - mossywell - 2012-12-13

OK, getting somewhere:
'{ "jsonrpc": "2.0", "method": "Player.GetProperties", "params": { "playerid": 0, "properties": ["speed"] }, "id": 1 }'

Now, what about the playerid? I click on that in the API and it says "Type: integer". Hmmm, OK, so at least I know not to try player.id 1.5, or Pi. Wink
What actually does playerid represent and how do I retrieve it's value? Player.GetActivePlayers sounds like it might be the thing? Nothing in the API documentation that relates Player.GetActivePlayers to playerid. It does tell me that it Returns: Type: array. An array of what? ActivePlayers one would assume, but what is the data type of an ActivePlayers.

I shall carry on guessing until something works...



RE: Help getting player state - N3MIS15 - 2012-12-13

Player.GetActivePlayers to get the player id
Request:
Code:
{
    'jsonrpc': '2.0',
    'id': 0,
    'method': 'Player.GetActivePlayers',
    'params': {},
}

Result:
Code:
{
    "jsonrpc": "2.0",
    "id": 0,
    "result": [
        {
            "playerid": 1,
            "type": "video"
        }
    ]
}

Player.GetItem to know what the player is playing

Request:
Code:
{
    'jsonrpc': '2.0',
    'id': 0,
    'method': 'Player.GetItem',
    'params': {'playerid': 1, 'properties': ['thumbnail']},
}

Result:
Code:
{
    "jsonrpc": "2.0",
    "id": 0,
    "result": {
        "item": {
            "type": "unknown",
            "thumbnail": "image://video@smb%3a%2f%2funraid%2fMUSIC%2fMachine%20Head%20-%20Darkness%20Within.mp4/",
            "label": "Machine Head - Darkness Within.mp4"
        }
    }
}

Once you figure out how the wiki/introspect works it becomes much easier Smile

EDIT: Player IDs are 0=music, 1=video, 2=pictures


RE: Help getting player state - mossywell - 2012-12-13

Thank you very much. What I could not see is where it says that Player.GetActivePlayers returns the PlayerID. I guess I should still consider it very much a work in progress.



RE: Help getting player state - Montellese - 2012-12-13

The presentation of the documentation on the wiki sucks but I don't have time to write (and especially keep up-to-date) the documentation manually for the whole API so I have written a very simple python script which generates what you see in the wiki. If you think there's not enough information you should always expand the "JSON Schema Description" (gray box) by clicking on the respective "show" link. That will give you the real JSON schema for the method you are looking at which contains all the information you need to know. In the case of Player.GetActivePlayers that will give you
Code:
{
  "params": [],
  "description": "Returns all active players",
  "returns": {
    "uniqueItems": true,
    "items": {
      "properties": {
        "type": {
          "$ref": "Player.Type",
          "required": true
        },
        "playerid": {
          "$ref": "Player.Id",
          "required": true
        }
      },
      "type": "object"
    },
    "type": "array"
  }
}
where you can see the "playerid" and the "type" properties which every item in the returned array provides.

PS: Currently playerids are 0=music, 1=video, 2=pictures but that might change in the future. The reason behind having Player.GetActivePlayers and having to pass a "playerid" to every Player method is that XBMC can have multiple players active at the same time (right now only slideshow and music) so you have to tell XBMC which player you want to control. HTTP-API wasn't able to do that because it didn't cover slideshows.


RE: Help getting player state - Mizaki - 2012-12-13

This reminds me. I'll try and get some examples up on the wiki page.


RE: Help getting player state - mossywell - 2012-12-13

@Montellese: Much appreciated. I don't like to sound like I'm complaining because I'm not: I know people have worked very hard to produce something that is completely free, so it is really appreciated.

@Mizaki: Yes, that would be really help. Cheers!


RE: Help getting player state - ndxtg - 2013-01-13

Am I missing something or is there another way to get "Now Playing" info? Because using the above method would miss alot of info.

For example, on the screen when playing a song, in now playing (fullscreen) mode I can see:
_ album cover (i.e. folder.jpg)
_ starttime, endtime of the song
_ song title

However, via JSON RPC, I retrieved all the fields of GetItem() with this specs Fields.All but only the following fields come back as result:
Code:
art: <<blank>>
fanart: <<blank>>
file: smb://MICRSVR/Music/Lossless/Album005/barbiegirl.wav
label: 02 - Barbie Girl Aqua.wav
thumbnail: <<blank>>
title: <<blank>>
type: unknown


Any help is appreciated.


RE: Help getting player state - Mizaki - 2013-01-13

I'll take a wild guess that the file isn't in the library ("type: unknown"). Therefore, there is no information to return. It's possible in some instances that the GUI has more access to information than the JSONRPC. You say all fields. I don't believe anyone (for good reason as anyone who has worked in IT will know) so make sure to post the exact command you are trying.