Solved xbmc.sleep() background
#1
Hello folks, I have Kodi 18.0ALPHA1, where is new function updateInfoTag() for xbmc.Player.  I run xbmc.Player().play(item, listitem) a then I want to use while loop and xmbc.sleep(ms) for updating new informations. Problem is, that there pops up a progress circle on screen disabling any activity. Is there solution for running it on background? time.sleep() doesnt work either. Thank you for any advice.

Image
Reply
#2
Post your code for assistance, FYI time.sleep and xbmc.sleep are no longer recommend. Use Kodis monitor class and waitforabort method.

https://codedocs.xyz/xbmc/xbmc/group__py...da904e8249

https://codedocs.xyz/xbmc/xbmc/class_x_b...video.html
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply
#3
Hi, thank you for helping. Code is simple but waitForAbort method do the same. Maybe threading would be solution?
python:
# -*- coding: utf-8 -*-
import xbmc
import xbmcgui
import xbmcplugin
import xbmcaddon
import requests
import os
import threading

class It(xbmcgui.ListItem):
    def __init__(self):
        xbmcgui.ListItem.__init__(self)

    def update_info(self):
        icon=os.path.join(xbmcaddon.Addon().getAddonInfo('path'),'icon.png')
        artist,song,fanart=get_info()
        self.setArt({"thumb":icon, "fanart":fanart, "icon":icon})
        self.setInfo("music", {"title": song, "artist": artist})

class RadioBeat(xbmc.Player):
    def __init__(self):
        xbmc.Player.__init__(self)

    def PlayRadio(self):
       stream="http://icecast2.play.cz/radiobeat128.mp3"
       it=It()
       it.setPath(stream)
       it.update_info()
       self.play(item=stream, listitem=it)
       xbmc.Monitor().waitForAbort(4)

    def InfoDaemon(self):
       while self.isPlayingAudio():
           it=It()
           it.update_info()
           it.setPath(xbmc.Player().getPlayingFile())
           self.updateInfoTag(it)
           xbmc.Monitor().waitForAbort(4)



def get_info():
    url="http://onair.play.cz/json/beat.json"
    r=requests.get(url)
    info=r.json()
    artist=info["artist"].title().encode('utf-8')
    song=info["song"].title().encode('utf-8')
    fanart=info["img"]
    return artist,song,fanart
    
xbmc.executebuiltin("ActivateWindow(12006)")
radio=RadioBeat()
radio.PlayRadio()
radio.InfoDaemon()

Reply
#4
The monitor class will do the same thing, but in a Kodi safe manner.

Line 33
python:
while isplaying
should be changed to
python:
while not xbmc.Monitor().abortRequested() and isplaying:

There are a number of issues with the code can you describe to me what you want to accomplish? it appears you want to play music and fill in meta data for it? if my assumption is correct you are going about it wrong Smile

You want to use listitems and pass that with the play command. But first I have to ask is this for a plugin or a script.... ie are you providing your own interface or do you want to use Kodis plugin dialog?
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply
#5
Well, thank you for advice. My problem is now solved - I have added setResolvedUrl() for listitem before starting play function and now it works.
python:
xbmcplugin.setResolvedUrl(int(sys.argv[1]), False , listitem=it)

My aim is to create plugin for playing online stream and updating infotags from online source not using addDirectoryItem(...)
Reply
#6
Your attached code above did not contain seturlresolve... so i'm guessing you are on the right track now. I'll mark the issue solved.
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply
#7
you have to decide whether you want to write a plugin or a script.
never mix and match plugin and script code like you're doing now.
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#8
@ronie is correct I missed your desire to avoid using adddirectory.

Setresolver must be used with adddirectory. You can't/shouldn't use xbmc.play within a plug-in only a script.
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply
#9
the code in the first post is a script, but likely it's defined as a plugin in the addon.xml file.
result: weird things will happen ;-)
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply

Logout Mark Read Team Forum Stats Members Help
xbmc.sleep() background0