Kodi Community Forum
v19 Control.setVisibleCondition & onControl don't work properly - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26)
+--- Thread: v19 Control.setVisibleCondition & onControl don't work properly (/showthread.php?tid=364694)



Control.setVisibleCondition & onControl don't work properly - burekas - 2021-09-30

Hi,

I have two buttons of Play and Pause, one above the other (The same x,y,w,h), kind of a toggle button.
The button visibilty is actually changed:
* When the Play icon is shown: When pressing on it, the Player start playing and the icon is changed to Pauses.
But when the Pause icon is shown: When pressing on it, the Player start playing again instead of pausing,
The onLoad function getting the control as the Play button id and not the Pause one, and the icon is of course stay on the Play icon.

What am I missing here?
Thanks.

Code:
self.play = xbmcgui.ControlButton(...)
self.pause = xbmcgui.ControlButton(...)

self.addControls([..., ... ,  self.prev, self.next])

# set visibility:
self.play.setVisibleCondition('[!Player.Playing]', True)      
self.pause.setVisibleCondition('[Player.Playing]', True)



    def onControl(self, control):
        _controlID = control.getId()
        if _controlID == self.pause.getId():
            Player().pause()
        elif _controlID == self.play.getId():
            Player().play(strm)



RE: Control.setVisibleCondition & onControl don't work properly - Roman_V_M - 2021-09-30

Try setFocus() on the active button when you toggle buttons.


RE: Control.setVisibleCondition & onControl don't work properly - burekas - 2021-09-30

(2021-09-30, 08:05)Roman_V_M Wrote: Try setFocus() on the active button when you toggle buttons.

I tried this like this:

Code:
    def onControl(self, control):
        
        _controlID = control.getId()
        if _controlID == self.pause.getId():
            Player().pause()
            self.setFocus(self.play)
        elif _controlID == self.play.getId():
            Player().play(...)
            self.setFocus(self.pause)

But still the same the "if _controlID == self.pause.getId():" never works,
all the time the "elif _controlID == self.play.getId():" works instead.


RE: Control.setVisibleCondition & onControl don't work properly - burekas - 2021-09-30

@Roman_V_M 

Ok I found the solution:
instead of using setFocus(), I'm using setEnable()

Code:
    def onControl(self, control):
     
        _controlID = control.getId()
        if _controlID == self.pause.getId():
            self.pause.setEnabled(False)
            self.play.setEnabled(True)           
            Player().pause()
        elif _controlID == self.play.getId():
            self.pause.setEnabled(True)   
            self.play.setEnabled(False)
            Player().play(...)

But the problem now is that the Player().pause() doesn't to its work, the Player continues to play.
However, Player().stop() does do the work.
So what is the difference between them, why does stop() actually stop the player while pause() doesn't do anything?