Getting Player status via Notification
#1
I am quite new to python, but I am trying to write an addon which can control my AVR. Depending on the content playing it should be set accordingly. For that, I need the type of content playing right after i got the notification that the player started.

So far I got

Code:
class DenonMonitor(xbmc.Monitor):
    
    myplayer=xbmc.Player()
    
    def __init__(self, *args, **kwargs):
        xbmc.Monitor.__init__(self)
                    
    def onNotification(self, sender, method, data):
        if method == "Player.OnPlay":
            PowerOn()
            if (myplayer.isPlayingAudio()):
                MusicMode()
            if (myplayer.isPlayingVideo()):
                MovieMode()
                
monitor = DenonMonitor()

However, I get the error log that "myplayer" is not defined in "onNotification". But I create it a few lines above. What am I doing wrong?
Reply
#2
It may be worth doing a bit of reading about class variables (and why "self" is always passed as the first variable in class methods).

That said, I'd rewrite your code like this:
Code:
class DenonMonitor(xbmc.Monitor):
      
    def __init__(self, *args, **kwargs):
        xbmc.Monitor.__init__(self)
        self.myplayer = xbmc.Player()
                    
    def onNotification(self, sender, method, data):
        if method == "Player.OnPlay":
            self.PowerOn()
            if (self.myplayer.isPlayingAudio()):
                self.MusicMode()
            elif (self.myplayer.isPlayingVideo()):
                self.MovieMode()

    def MusicMode(self):
        pass

    def MovieMode(self):
        pass

    def PowerOn(self):
        pass
                
monitor = DenonMonitor()
I assume there's more to your code than this, but hopefully this will help you on your way. It's also worth noting that the "data" variable in the notification should contain some more information about what's being played (e.g. Movie) etc. but I suspect your "isPlayingVideo" call is sufficient.

Edit: updated to include PowerOn method in clas..
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply

Logout Mark Read Team Forum Stats Members Help
Getting Player status via Notification0