Can't stop Player() in xbmc
#1
When i use this function to set the subtitle file for the player, i can't stop player(), after stop it, it auto replay, and forever :
Code:
def play(url, play=False):
    playlist = xbmc.PlayList(1)
    playlist.clear()
    thumb=''
    info = xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=thumb)
    playlist.add(url, info)
    fname="sub.srt"
    subtitle=xbmc.translatePath( os.path.join( home, fname ))
    xbmc.Player().play(playlist)
    xbmc.Player().setSubtitles(subtitle.encode("utf-8"))
Reply
#2
Are u calling this function from a xbmc addon menu entry? Make sure you set isfolder=False when calling addDirectoryItem(...).
Reply
#3
(2014-07-09, 19:47)enen92 Wrote: Are u calling this function from a xbmc addon menu entry? Make sure you set isfolder=False when calling addDirectoryItem(...).

If i use False, it won't be play Sad
Reply
#4
This is my class :
Code:
class Play():

    def __init__(self, link, subtitle, dat):
        dat = utils.decode(dat)
        playlist = xbmc.PlayList(1)
        playlist.clear()
        tit = dat['title'] + ' | [COLOR blue]Chapter : ' + dat['chap'] + '[/COLOR]'
        li = xbmcgui.ListItem(tit, tit, dat['thumb'], '')
        li.setProperty('isPlayable', 'true')
        li.setProperty('mimetype', 'video/x-msvideo')
        playlist.add(utils.fix(link), li, 0)
        xbmc.Player().play(playlist)
        if subtitle != '':
            xbmc.Player().setSubtitles(utils.fix(subtitle).encode("utf-8"))
Reply
#5
The problem is not in this block of code but on the way you create the directoryitems as I said before. Please post the full code.
Reply
#6
(2014-07-10, 18:51)enen92 Wrote: The problem is not in this block of code but on the way you create the directoryitems as I said before. Please post the full code.

I know Big Grin, if I use isFolder=True, the player() will be autoreplay, if I use isFolder=False, it won't be play, it open stream and autoclose

This is the function which addDir

Code:
def chap(child, dat):
    dat = utils.decode(dat)
    opener = utils.opener()
    child = 'watch' + child[5:]
    html = opener.open(utils.homepage + child).read()
    unsub = False
    lis = re.compile('_link="(.+?)" _sub="(.+?)" class="left cursorP" style="margin-bottom:5px;">').findall(html)
    if len(lis) == 0:
        lis = re.compile('_link="(.+?)" _sub="" class="left cursorP" style="margin-bottom:5px;">').findall(html)
        unsub = True
    utils.addDir('[COLOR green]' + dat['title'] + '[/COLOR]', '', False, dat['thumb'])
    for i in range(len(lis)):
        dat['chap'] = str(i + 1)
        if unsub:
            utils.addDir('      + Chapter ' + str(i + 1), utils.buildUrl(
                {'mode': 'play', 'link': urllib.quote(lis[i]), 'subtitle': '',
                 'data': utils.encode(dat)}), False, dat['thumb'])
        else:
            utils.addDir('      + Chapter' + str(i + 1), utils.buildUrl(
                {'mode': 'play', 'link': urllib.quote(lis[i][0]), 'subtitle': urllib.quote(lis[i][1]),
                 'data': utils.encode(dat)}), False, dat['thumb'])
    opener.close()

Hey, i solved, i found that if we setProperty to the listitem, it won't be play
Thanks for you help Big Grin
Reply
#7
add a while loop to sleep xbmc if it's playing:

xbmc.Player().setSubtitles(subtitle.encode("utf-8"))
while xbmc.Player().isPlaying:
xbmc.sleep(5000)
Reply
#8
(2014-07-11, 02:01)enen92 Wrote: add a while loop to sleep xbmc if it's playing:

xbmc.Player().setSubtitles(subtitle.encode("utf-8"))
while xbmc.Player().isPlaying:
xbmc.sleep(5000)

You read my reply again Big Grin, i solved, because if setProperty for Listitem, it won't be play
Reply

Logout Mark Read Team Forum Stats Members Help
Can't stop Player() in xbmc0