Kodi Community Forum

Full Version: xbmc.Player().isPlaying()?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
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() :
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.
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