Posts: 17
Joined: Feb 2014
Reputation:
0
Scores
Junior Member
Posts: 17
2014-03-29, 19:09
Hi,
I'm trying to get into JSON. I can't figure out how to use OnVolumeChanged. It must be something like
{\"jsonrpc\": \"2.0\", \"notification\": \"Application.OnVolumeChanged\", \"params\":
{\"sender\": sender,
\"data\": volume, muted }
}
This gives parse error: {"error":{"code":-32700,"message":"Parse error."},"id":null,"jsonrpc":"2.0"}
What is to be used for sender?
How do I use the data array?
Are there some examples for notifications I overlooked?
Any help welcome.
Thx!!
Posts: 5,184
Joined: Jan 2009
Reputation:
131
You can't call notifications. Notifications are sent to you by XBMC when something happens (in the case of OnVolumeChanged when the volume has changed) over TCP or WebSockets.
You want to use Application.SetVolume.
Always read the
online manual (wiki),
FAQ (wiki) and search the forum before posting.
Do not e-mail Team Kodi members directly asking for support. Read/follow the
forum rules (wiki).
Please read the pages on
troubleshooting (wiki) and
bug reporting (wiki) before reporting issues.
Posts: 17
Joined: Feb 2014
Reputation:
0
Scores
Junior Member
Posts: 17
Hi Montellese,
Thank you for your reply.
I understand your explanation.
I want to subscribe to this notification and get the volume level when there is a change in volume.
Getting the volume level can be done through Application.GetProperties. That works for me.
Setting the volume through Application.SetVolume, as you mentioned.
Is there a possibility to subscribe to this notification from within an add on?
And how does that work?
Posts: 5,184
Joined: Jan 2009
Reputation:
131
In a python addon you can provide a class that derives from the Monitor class which has an OnNotification() method which you can overwrite. In there you will receive all JSON-RPC notifications.
Always read the
online manual (wiki),
FAQ (wiki) and search the forum before posting.
Do not e-mail Team Kodi members directly asking for support. Read/follow the
forum rules (wiki).
Please read the pages on
troubleshooting (wiki) and
bug reporting (wiki) before reporting issues.
Posts: 17
Joined: Feb 2014
Reputation:
0
Scores
Junior Member
Posts: 17
2014-03-30, 20:36
(This post was last modified: 2014-03-30, 21:26 by Scores.)
Ok, thanks for pointing direction.
I tried xbmc.Player and xbmc.Monitor.
class MyPlayer(xbmc.Player):
def __init__(self):
xbmc.Player.__init__(self)
def onPlayBackStarted(self):
logging('player starts')
This in fact works. When music starts playing onPlayBackStarted is called. "player starts" appears in logging.
Now trying to do the same with xbmc.Monitor. However I don't know how to get the Announcement OnVolumeChanged. I think it must be something like:
class MyMonitor(xbmc.Monitor):
def __init__(self, *args, **kwargs):
xbmc.Monitor.__init__(self)
def onNotification(self,sender,method,data):
logging('notification sent')
logging('sender = "' + sender + '"')
logging('method = "' + method + '"')
logging('data = "' + data + '"')
if method == "Player.OnPlay":
logging('notification Player.OnPlay')
elif method == "Application.OnVolumeChanged":
logging('notification Player.OnVolumeChanged')
Any thoughts about why onNotifications is not called?
I'm using Frodo. Seems like onNotifications does not work on Frodo yet?
If so, how do I get notifications on Frodo?
How do I get Application.OnVolumeChanged notifications?
I'm so lost......
Posts: 5,184
Joined: Jan 2009
Reputation:
131
It doesn't work in Frodo and the only way to get notifications in Frodo is by opening a TCP socket to XBMC on port 9090 (but it's configurable in advancedsettings.xml). But that only works if "Allow programs on this system to control XBMC" is enabled in Settings -> Services -> Remote Control.
In Gotham you will be able to use the much simpler xbmc.Monitor.onNotification approach.
Always read the
online manual (wiki),
FAQ (wiki) and search the forum before posting.
Do not e-mail Team Kodi members directly asking for support. Read/follow the
forum rules (wiki).
Please read the pages on
troubleshooting (wiki) and
bug reporting (wiki) before reporting issues.
Posts: 794
Joined: Apr 2011
Reputation:
16
Mizaki
Posting Freak
Posts: 794
Websocket is probably easiest.