2024-05-27, 18:33
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?!
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)