[JSON-RPC]: HowTo use Notification OnVolumeChanged
#1
Question 
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!!
Reply
#2
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.
Reply
#3
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?
Reply
#4
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.
Reply
#5
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......
Reply
#6
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.
Reply
#7
(2014-03-30, 21:43)Montellese Wrote: 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.

Sorry to hijack the thread, but how can I subscribe to notifications over JSON-RPC? (Can I, at all?) I am developing a remote control app and would like to know when something happens on the server so that I can update the UI in my app.
Reply
#8
Websocket is probably easiest.
Image
AWXi - Ajax web interface. Wiki
Reply

Logout Mark Read Team Forum Stats Members Help
[JSON-RPC]: HowTo use Notification OnVolumeChanged1