Addon is restarting again when player stopped/done
#1
I have an addon, that one of the list items is a "Search" button (url with mode=4) which opens the keyboard,
the results of this search create line items with playable links (url with mode=3 each item).
Each link is played by using this function: "xbmcplugin.setResolvedUrl".

The problem is when I stop the player when ~70% of it was played (Or some other threshold) or finished to play,
the addon is running again with the previous mode (mode=4, "search"),
It causes the keyboard to show up again instead of showing the previous menu with the results of the last search,
And even closing it with Esc, it actually run a search again with empty text, so it shows an empty results list.

Just to mention, when I stop the player few seconds after for example, it's ok.

So my question why does it behave like this?
How can I avoid it?

Thanks.

python:
if mode == 0:
    main_menu()
elif mode == 2:
    category(url, iconimage, fanart)
elif mode == 3:
    play_link(name, url)
elif mode == 4:
    search()
Reply
#2
Anyone please?
Reply
#3
need to see surrounding code to make any assessments, the conditional doesn't indicate the issue
Reply
#4
@izprtxqkft

The issue is more with the Kodi Player behavior when it stops in different times and less the addon code I think.
1. Immediately on start
2. When it finished or in an advanced part of the media.

On (1) Kodi doesn't call the addon again, so when the play stops, I still get the previous search results as a list.
But on (2) Kodi call the addon again when the url contains the mode for search which popup the keyboard again, so even press on Esc, execute the search again with an empty string.
But I don't want it to happen, I want it like (1), getting the previous search results without calling the addon again with the search mode.

python:
def search():
    search_entered = ''
    keyboard = xbmc.Keyboard(search_entered, 'Search')
    keyboard.doModal()
    if keyboard.isConfirmed():
        _params = ('Sstr', keyboard.getText()),
        response = get_url('https://www.karaoke.co.il/searchresults.php', params=_params)
        parse_results_from_response(response)

python:
def parse_results_from_response(response):
    pattern = r'src="(.+?)" alt="(.+?)" title="(.+?)" /> <a href="(.+?)" title="(.+?)"'
    matches = re.findall(pattern, response)
    myLog("parse_results_from_response: " + repr(matches))
    for match in matches:
        image, desc, title, url, title2 = match
        image = get_better_image(image)
        add_link(title, url, 3, False, image, image, desc)

python:
def add_link( name, url, mode, isFolder, iconimage, fanart, description, data=''):
    params = {}
    params['url'] = url
    params['mode'] = mode
    params['data'] = data
    params['iconimage'] = iconimage
    params['fanart'] = fanart
    params['description'] = description
    x = name.split("Playback")
    name = x[1]
    all_ur = utf8_urlencode(params)
    _url = sys.argv[0] + "?mode=" + str(mode) + '&' + all_ur
    menu_items = []
    menu_items.append(('video Data', 'RunPlugin(%s)' % ('%s?url=%s&mode=4')%(sys.argv[0],str(url))))
    menu_items.append(('Links from video', 'RunPlugin(%s)' % ('%s?url=%s&mode=3')%(sys.argv[0],str(url))))
    video_info = {}
    name = name.replace('&', '&')
    video_info['title'] = name
    video_info['plot'] = description
    #u=sys.argv[0]+"?url="+que(url)+"&mode="+str(mode)+"&name="+que(name)
    try:
        liz = xbmcgui.ListItem(label = name, label2 = name)
        liz.setArt({'thumb' : iconimage, 'poster': iconimage, 'fanart': iconimage, 'icon': iconimage})
    except:
        liz = xbmcgui.ListItem(label = name, label2 = name, thumbnailImage = iconimage, iconImage = iconimage)
    liz.addContextMenuItems(menu_items, replaceItems=False)
    liz.setInfo(type="Video", infoLabels=video_info)
    liz.setProperty("IsPlayable","true")
    xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=_url, listitem=liz, isFolder=isFolder)

python:
def play_link(name,url):
    response = get_url(url)
    f_link=(response.json()['data']['playback'])
    final_link = '{0}|User-Agent={1}'.format(f_link, __USERAGENT__)
    final_link = final_link.replace("download", "show")
    listItem = xbmcgui.ListItem(path=final_link)
    listItem.setInfo(type='video', infoLabels={'title':name,'plot':''})
    listItem.setProperty('IsPlayable', 'true')
    xbmcplugin.setResolvedUrl(handle=int(sys.argv[1]), succeeded=True, listitem=listItem)
Reply
#5
This is actually the exact same issue I'm running into and I really don't want to have to encode state into each URL or manage state through saving to JSON which would slow down the addon so much.

Closest I have gotten to better behaviour is to use the following:

python:
xbmc.executebuiltin('Container.Update(%s, replace)' % url)

This updates the current container's url and replaces it in history. So instead of feeding the response from the keyboard straight to the method it re-triggers navigation with a query param.
The major issue I have is now the history of searches is lost as I'm replacing the URL every time. I've lost going backwards but the behaviour is a little better.
I really would like to retain both the history and search functionality without having to write my own state management solution.

You can take a look at my github repo where I've done a minimal implementation of this here: Github Repo

If I have any luck then I'll post here my solution and update the repo.
Reply
#6
@CrudeCreator
I don't sure that we need to create any kind of state management.
My question is based on the Kodi Player, why does a different position of Stop behave differently?
When stopping the player at the start it's ok, but when the player is finished or stopped in an advanced position, kodi run the addon again with previous url (Actually the url of the current addon menu)
Reply
#7
(2023-12-16, 16:19)burekas Wrote: @CrudeCreator
I don't sure that we need to create any kind of state management.
My question is based on the Kodi Player, why does a different position of Stop behave differently?
When stopping the player at the start it's ok, but when the player is finished or stopped in an advanced position, kodi run the addon again with previous url (Actually the url of the current addon menu)

I'm not familiar with this part of Kodi functionality but my guess is that it's connected to tracking playback progress and displaying "in progress" and "watched" marks on video items. Kodi has a "grace treshold" at the beginning of video whey progress is not yet tracked but after that when playback is stopped/finished it needs to re-read the current virtual folder to refresh "in progress"/"watched" state for the current item. And for plugin re-reading a virtual folder means re-executing this plugin URL.
Reply
#8
(2023-12-16, 19:05)Roman_V_M Wrote:
(2023-12-16, 16:19)burekas Wrote: @CrudeCreator
I don't sure that we need to create any kind of state management.
My question is based on the Kodi Player, why does a different position of Stop behave differently?
When stopping the player at the start it's ok, but when the player is finished or stopped in an advanced position, kodi run the addon again with previous url (Actually the url of the current addon menu)

I'm not familiar with this part of Kodi functionality but my guess is that it's connected to tracking playback progress and displaying "in progress" and "watched" marks on video items. Kodi has a "grace treshold" at the beginning of video whey progress is not yet tracked but after that when playback is stopped/finished it needs to re-read the current virtual folder to refresh "in progress"/"watched" state for the current item. And for plugin re-reading a virtual folder means re-executing this plugin URL.

Make sense.
Is there any way to disable this behavior specific on this case here when playing a video file?
Because it makes the addon run again in unwanted mode as I described.
Reply
#9
(2023-12-16, 21:47)burekas Wrote: Make sense.
Is there any way to disable this behavior specific on this case here when playing a video file?
Because it makes the addon run again in unwanted mode as I described.

I don't know. You can try to play with cacheToDisc parameter of endOfDirectory() function but I'm not sure if it helps. I see 2 options:
1) Try to decouple entering search text and displaying search results. After you enter a text you call another route of your plugin with RunPlugin built-in function that will fetch and display search result for the entered text. The only problem I see that it can mess with UI navigation history. Note, that you must use isFolder=False in addDirectoryItem if your list item does anything else other than displaying a sub-listing.
2) After performing a search leave some global flag in a shared Kodi memory (an xbmcgui.Window property) that will signal not to open a virtual keyboard again but display previous search results when playback stops and Kodi tries to load the same plugin route. But you need to clear this flag somehow to enable a new search.
Reply
#10
(2023-12-19, 23:36)Roman_V_M Wrote:
(2023-12-16, 21:47)burekas Wrote: Make sense.
Is there any way to disable this behavior specific on this case here when playing a video file?
Because it makes the addon run again in unwanted mode as I described.

I don't know. You can try to play with cacheToDisc parameter of endOfDirectory() function but I'm not sure if it helps. I see 2 options:
1) Try to decouple entering search text and displaying search results. After you enter a text you call another route of your plugin with RunPlugin built-in function that will fetch and display search result for the entered text. The only problem I see that it can mess with UI navigation history. Note, that you must use isFolder=False in addDirectoryItem if your list item does anything else other than displaying a sub-listing.
2) After performing a search leave some global flag in a shared Kodi memory (an xbmcgui.Window property) that will signal not to open a virtual keyboard again but display previous search results when playback stops and Kodi tries to load the same plugin route. But you need to clear this flag somehow to enable a new search.
This is the problem, how can I know when to clear this flag?
Reply
#11
(2023-12-21, 00:59)burekas Wrote: This is the problem, how can I know when to clear this flag?

For example, you can clear it when you go open the higher level of navigation. I'd recommend you to try different options.
Reply
#12
Cross-referencing some sorcery using a combination of things to get the desired flow, see Edit 2:
https://forum.kodi.tv/showthread.php?tid...pid3176901
Reply
#13
(2023-12-22, 20:57)Roman_V_M Wrote:
(2023-12-21, 00:59)burekas Wrote: This is the problem, how can I know when to clear this flag?

For example, you can clear it when you go open the higher level of navigation. I'd recommend you to try different options.
I was able to produce a satisfactory solution inspired by you, which works very well. Thanks.

Focus on: 'showKeyboard' and 'keyborad_text' properties.

python:
def search():
    search_entered = ''
    keyboard = xbmc.Keyboard(search_entered, 'Search')

    window = xbmcgui.Window(xbmcgui.getCurrentWindowId())
    if window.getProperty('showKeyboard') == 'true':
        keyboard.doModal()
        if keyboard.isConfirmed():
            keyboard_text = keyboard.getText()
            window.setProperty('keyborad_text', keyboard_text)
            run_search(keyboard_text)
    else:
        window.setProperty('showKeyboard', 'true')
        #show last results (actually run the same last search query)
        keyboard_text = window.getProperty('keyborad_text')
        run_search(keyboard_text)

python:
def main_menu():
    window = xbmcgui.Window(xbmcgui.getCurrentWindowId())
    window.setProperty('showKeyboard', 'true')
    .
    .

python:
def play_link(name,url):
    .
    .
    window = xbmcgui.Window(xbmcgui.getCurrentWindowId())
    window.setProperty('showKeyboard', 'false')

    xbmcplugin.setResolvedUrl(handle=int(sys.argv[1]), succeeded=True, listitem=listItem)
Reply

Logout Mark Read Team Forum Stats Members Help
Addon is restarting again when player stopped/done0