Addon with infinite running loop?
#1
Hi @all

>>>> Because my post got blocked, i had to use sl*ep instead of the word with the two e's......

I am currently developing an addon for an internet radio station. This station not only provides audio streams in various bitrates and formats, they provide also a extensive songinfo, a HD-slideshow and a voting system. I have completed the first function, playing the audio stream without any troubles.

Now, the next functionality i wanted to add ist a mechanism to execute different functions periodically on a unix timebase in a grain of one second. My current attempt look like this:
Code:
while 1
    xbmc.sl*ep(1000)
    if time() > time_to_execute_slideshow_update:
        slideshow_update()
    if time() > time_to_execute_some_function:
        do_some_other_function()

    ....etc....

    if request_for_voting
        do_voting()
    if request_for_exit
        break

The problem is, that xbmc.sl*ep(msecs) causes kodi to display the "working" notification and it seems that i cant do anything than interrupt the loop. I tried "time.sl*ep(secs)" which throws me some errors.

May it be better to do the timed tasks with a discrete service plugin?

Furthermore, it isnt clear for me how to handle the "background" of the player. Should I do the whole the whole slideshow thing with a discrete vizualisation plugin?

Thanks forward!

selli69
Reply
#2
You might look at spinning of a separate thread to do the loop. That's what I do with SpeedFan Information Display. That keeps the addon from locking while it sleeps. Here's the link to the github page for that addon so you can look at the code:

https://github.com/pkscout/script.speedfaninfo

One really important thing is the xbmc.abortRequested in the while loop. You absolutely must have this somewhere, as this tells addons that Kodi is trying to quit. If you don't have this, your addon will keep Kodi from exiting.
Reply
#3
Thanks for your reply! I did a look at your Code and have found some good concept for my upcoming work. I also had a look at Artst Slideshow where I found some ideas also. thx!
Reply

Logout Mark Read Team Forum Stats Members Help
Addon with infinite running loop?0