Solved premature/assynchronous fire of playerEvent?
#1
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
Reply
#2
tag reader is async..
Reply
#3
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.
Reply
#4
This is why you find xbmc.sleep() all over the place in scripts messing with the player.
Reply
#5
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
Reply
#6
(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.
Reply
#7
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
Reply

Logout Mark Read Team Forum Stats Members Help
premature/assynchronous fire of playerEvent?0