Kodi Community Forum

Full Version: Get Filename and playing state from Player
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi Forum,

I am working on a service addon where I recurringly (once per second at least) get the state of the player and which file is playing

I therefore have the following code (simplyfied):

python:

if __name__ == '__main__':
  monitor = xbmc.Monitor()
  xbmc.log("Starting wind machine", xbmc.LOGWARNING)
    
  while not monitor.abortRequested():
    if (xbmc.Player().isPlaying()):
      currentFileName = xbmc.Player().getPlayingFile()
      xbmc.log("Playing: " + currentFileName, xbmc.LOGWARNING)
      # do something with file
    xbmc.log("Playing stopped", xbmc.LOGWARNING)

I have 2 problems:
1.) CurrentFielname is always empty.
2.) When I seek in a playing movie xbmc.Player().isPlaying() is quickl alternating between true and false a couple of times before settling to false even though the file is still playing

I have to note that the movie is not part of the library but simply a video file I had lying around for testing

Can you tell my why isPlaying() is behaving like that and how to get the filename of the currently playing file?

Thanks in advance.

Best
LuigiEd
1)
python:
json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "xbmc.GetInfoLabels", "params":{"labels": ["player.Filename"]}, "id": 1}' )
file_playing = _json.loads(json_query).get('result').get('player.Filename')

2) No idea, sorry
Thank you, I will try that one out.

Is there any other way to find out if there is currently something playing?
Yeah, Player.HasMedia.  I think your issue is that (according to the wiki) Player.Playing only returns true if Kodi is actually playing something, and will return false if it's paused, rewinding or fastforwarding.

So something like
python:
if __name__ == '__main__':
    monitor = xbmc.Monitor()
    xbmc.log("Starting wind machine", xbmc.LOGWARNING)

while not monitor.abortRequested():
    if (xbmc.getCondVisibility("Player.HasMedia")):
        currentFileName = xbmc.getInfoLabel("Player.Filename")
        xbmc.log("Playing: " + currentFileName, xbmc.LOGWARNING)
        # do something with file
    xbmc.log("Playing stopped", xbmc.LOGWARNING)