Kodi Community Forum

Full Version: premature/assynchronous fire of playerEvent?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all,

In my quest to get Kodi to do what I want, I have now seen myself forced to enter into service script territory.
But it seems I need help with my workaround, as things are perhaps not what they appear to be?

getMusicInfoTag often returns information from the last played song - I would think it should return info from the song about to play.
Anyways, How would I make sure I get the information from the song (about to) play?

With the code posted, the window properties I set with info from the getMusicInfoTag are really often filled with info from the previous played track!

Code:
# MEDIA PLAYER INTERCEPTOR
class PlayerEvents(xbmc.Player) :
  
    def onPlayBackStarted(self):
    
        xbmc.sleep(200) #<!-- The workaround solution..

        MUSICINFOTAG = xbmc.Player().getMusicInfoTag()
        TIT = MUSICINFOTAG.getTitle()
        GEN = MUSICINFOTAG.getGenre()

        WINDOW.setProperty( 'mediaPlayerCurrentTitle', TIT)
        WINDOW.setProperty( 'mediaPlayerCurrentCover', GEN)

SOLUTION: Added xbmc.sleep(200) to the code.

(WINDOW is set to the home window)

16.0-BETA2 Git:20151115-07f691e
tag reader is async..
Ofcourse...

Thanks ironic_monkey.

Well.. time to find a workaround to my workaround to the fixed up workaround to fix what wasn't broken but just plain annoying.
This is why you find xbmc.sleep() all over the place in scripts messing with the player.
And that seems to be just the workaround I needed.
Adding xbmc.sleep(200) before my polling of the info seems to make it work. Thanks Smile
(2015-11-20, 15:53)Torben Wrote: [ -> ]And that seems to be just the workaround I needed.
Adding xbmc.sleep(200) before my polling of the info seems to make it work. Thanks Smile
Yeah 200 seems to be the "platform-independent", reliable delay needed for most things other than setting sub-titles for videos on pre-Helix versions - which needs more like 1000 (1 sec). Helix or higher has the lovely xbmcgui.listitem.setSubtitles() method that eliminates waiting on the player.

Just a quick note about xbmc.sleep() that has been in the addon dev email group, but I haven't seen in the forum. Apparently there has been some abuse in setting long sleep times which causes issues with timely shutdown/exiting Kodi. If you need to use an extended sleep ( above a sec or two) you need to put it in a loop which uses xbmc.Monitor.waitForAbort(). Just bear in mind that the xbmc.sleep uses millisecs, waitForAbort uses seconds.
Thanks again.
I have this in the bottom of my service, as I believe it should be:
Code:
#End if requested:
while not monitor.abortRequested():
    if monitor.waitForAbort(10):
        break