Kodi Community Forum
setResolvedUrl() executes in one scenario, not in another - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26)
+--- Thread: setResolvedUrl() executes in one scenario, not in another (/showthread.php?tid=377715)



setResolvedUrl() executes in one scenario, not in another - hookum - 2024-05-27

Hi all,

I am developing my addon, and running into a strange problem. The addon plays several streams, one after the other. Notice that both @plugin functions call play_video_source(). When this is done via the top function, play_video(), all is well, and the addon behaves as expected (calling xbmcplugin.setResolvedUrl()  plays the videos). However, when execution travels through the second function, select_video_source(), setResolvedUrl() never executes (the videos don't play), although the logging lines above and below it do.

What's going on here?!

Code:

@plugin.route('/play/<path:video_source_url>')
def play_video(video_source_url):
  # Parse passed-in URL
  url = urllib.parse.unquote(urllib.parse.unquote(video_source_url))
  xbmc.log("Playing playlist at URL: {}".format(video_source_url), xbmc.LOGINFO)
  # Get "best" video source
  video_source_list = VIDEO_SOURCE_REPO.fetch_video_source_list(url)
  video_source = video_source_list.get_preferred_source()
  play_video_source(video_source)


@plugin.route('/video/select_video_source/<path:video_source_url>')
def select_video_source(video_source_url):
  video_source_list = VIDEO_SOURCE_REPO.fetch_video_source_list(video_source_url)
  xbmc.log("Retrieved playlist: {}".format(video_source_list), xbmc.LOGINFO)

  sources = []
  for variant in video_source_list.variants:
    item = xbmcgui.ListItem(label="{}".format(variant))
    sources.append(item)

  # display select video source dialog
  dialog = xbmcgui.Dialog()
  selected_idx = dialog.select('Select video source', sources)
  # handle dialog selection; -1 = cancel
  if selected_idx != -1:
    selected = video_source_list.get_variant_source(selected_idx)
    play_video_source(selected)


def play_video_source(video_source):
  global __handle__
  global MAX_VIDEO_RETRIES

  xbmc.log("Playing Video Source: {}".format(video_source), xbmc.LOGINFO)
  items = video_source['uris']

  # begin playing first item
  item = items[0]
  list_item = xbmcgui.ListItem(path=item['uri'], label=item['title'])
  list_item.setContentLookup(False)
  list_item.setMimeType("application/mpegurl")
  xbmc.log("About to play", 1)
  xbmcplugin.setResolvedUrl(__handle__, True, listitem=list_item)
  xbmc.log("Should be playing!", 1)

  # add remaining items to playlist
  kodi_playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
  for item in items[1:]:
    li = xbmcgui.ListItem(label=item['title'])
    li.setContentLookup(False)
    li.setMimeType("application/mpegurl")
    url = item['uri']
    kodi_playlist.add(url=url, listitem=li)



RE: setResolvedUrl() executes in one scenario, not in another - hookum - 2024-05-27

Ok, I've made a little progress. The variable __handle__ which in earlier code is

Code:
__handle__ = int(sys.argv[1])

is equal greater than 0 when the video DOES play (14, 19, etc.), and -1 when it doesn't. I am guessing this is my problem. So what is this argument, and where does it come from?

EDIT: Even when passing in the handle manually, or hard-coding it to ex: 14, still does not play when returning from the Dialog(). Weird...

EDIT #2: The function select_video_source() above is called thusly:

Code:

select_video = PLUGIN.url_for(select_video_source, playlist_url)
list_item.addContextMenuItems([('Select source...', 'RunPlugin(%s)' % select_video)])



RE: setResolvedUrl() executes in one scenario, not in another - hookum - 2024-05-28

Kept at it, and got it sorted. Thanks to this very helpful post. I simply changed
Code:
RunPlugin(...)

to
Code:
PlayMedia(...)

and problem solved.