Kodi Community Forum
xbmc.Player().isPlaying()? - 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: xbmc.Player().isPlaying()? (/showthread.php?tid=199192)



xbmc.Player().isPlaying()? - tungmeister - 2014-07-03

I'm very new to python so I'm just experimenting making a little script at the moment however I'm having trouble checking if xbmc is playing: I've got this section of code however the if statement is always passed even when something is playing. I thought that xbmc.Player().isPlaying() should return true when something is playing, I've probably got something wrong somewhere but anyway here's the code:
PHP Code:
def _play_episode(selfgenre) :
        
xbmc.executebuiltin("PlayMedia("str(self._playlist_path(genre)) +".xsp)")
        if  
xbmc.Player().isPlaying() :
            if 
info == "true" :
                
xbmc.executebuiltin("ActivateWindow(fullscreeninfo)")
                
time.sleep(dur)
                
xbmc.executebuiltin("Dialog.Close(fullscreeninfo)"
                exit()
            else :
                exit()
        else :
            
self._error_msg(genre)
            exit() 

Can someone point out what's wrong?


RE: xbmc.Player().isPlaying()? - jorgercosta - 2014-07-03

Maybe you are going to fast, i think should xbmc.sleep(500) between xbmc.executebuiltin("PlayMedia("+ str(self._playlist_path(genre)) +".xsp)")
and
if xbmc.Player().isPlaying() :


RE: xbmc.Player().isPlaying()? - tungmeister - 2014-07-03

That was my initial thought, I've tried sleeping for several seconds yet it still behaves as though xbmc.Player().isPlaying() is returning false as far as I can see.

EDIT: I've tried with xbmc.sleep() as you suggested and now it's working fine, I was using time.sleep() before I wasn't aware of the xbmc method or that it would behave differently. Thanks for the help.


RE: xbmc.Player().isPlaying()? - enen92 - 2014-07-04

Maybe it is better to execute that section of the code only when playback has started. Create a new Inheritance of the XBMC player to execute actions on specific player events:


PHP Code:
class Player(xbmc.Player):
    
def __init__(self):
        
xbmc.Player.__init__(self)
        print(
"player initialized")


    
def onPlayBackStarted(self):
        print(
"player Started")
        if 
info == "true" :
                
xbmc.executebuiltin("ActivateWindow(fullscreeninfo)")
                
xbmc.sleep(dur#1000 = 1sec
                
xbmc.executebuiltin("Dialog.Close(fullscreeninfo)"


    
def onPlayBackStopped(self):
           print(
"player stopped")

    
def onPlayBackEnded(self):
        
self.onPlayBackStopped() 

To call the player just use:

PHP Code:
xbmcPlayer xbmc.Player(xbmc.PLAYER_CORE_AUTO)
xbmcPlayer.play(your_video_file