Solved 'Attempt to use invalid handle -1' error
#1
I am learning Python through the development of a Kodi add-on. I am trying to display an image using the xbmcplugin.setResolvedUrl() function but I get an error:
Quote:'Attempt to use invalid handle -1' error.
I am getting rid of the error when including li.setProperty("IsPlayable", "true") in my addFile function but then the image is not displayed. What am I doing wrong?
 
Code:
import sys
import urllib
import urlparse
import xbmcgui
import xbmcplugin
import xbmcaddon

my_addon = xbmcaddon.Addon()
addon_path = xbmc.translatePath(my_addon.getAddonInfo('path'))
base_url = sys.argv[0]
addon_handle = int(sys.argv[1])
args = urlparse.parse_qs(sys.argv[2][1:])
mode = args.get('mode', None)

def build_url(query):
    return base_url + '?' + urllib.urlencode(query)

def addFile(filename, filepath):
    filedir = build_url({'mode': 'display', 'filepath': filepath})
    li = xbmcgui.ListItem(filename)
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=filedir, listitem=li)

def displayImage(url):
    li = xbmcgui.ListItem('Sample image')
    li.setPath(url)
    xbmcplugin.setResolvedUrl(addon_handle, True, listitem=li)

if mode is None:
    fileurl = 'https://elmicrolector.files.wordpress.com/2016/10/breu-14-a1.jpg'
    addFile('Sample image', fileurl)
    xbmcplugin.setContent(addon_handle, 'files')
    xbmcplugin.endOfDirectory(addon_handle)

elif mode[0] == 'display':
    displayImage(args['filepath'][0])
Reply
#2
you have to include li.setProperty('IsPlayable','true') in addFile. if not you are not actually getting a resolveUrl playback.
Reply
#3
When I include li.setProperty("IsPlayable", "true") in my addFile function the error is not shown but then the image is not displayed. It looks like I am notgetting a resolveUrl playback.
Reply
#4
did you mark the listitem as a file ?
Reply
#5
Sorry, what do you mean?
Reply
#6
My quick experiments showed that setResolvedUrl plugin path does not work for photos, like it does for videos, unless I'm missing some non-obvious option. For photos only direct URLs are working.
Reply
#7
You are absolutely right! When I replace the url of the photo with a url of a video and I include li.setProperty("IsPlayable", "true") in my addFile function, the xbmcplugin.setResolvedUrl() function works fine.
Reply

Logout Mark Read Team Forum Stats Members Help
'Attempt to use invalid handle -1' error0