Kodi Community Forum
Solved 'Attempt to use invalid handle -1' error - 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: Solved 'Attempt to use invalid handle -1' error (/showthread.php?tid=328080)



'Attempt to use invalid handle -1' error - Etchot - 2018-02-04

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])



RE: 'Attempt to use invalid handle -1' error - spiff - 2018-02-06

you have to include li.setProperty('IsPlayable','true') in addFile. if not you are not actually getting a resolveUrl playback.


RE: 'Attempt to use invalid handle -1' error - Etchot - 2018-02-06

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.


RE: 'Attempt to use invalid handle -1' error - spiff - 2018-02-06

did you mark the listitem as a file ?


RE: 'Attempt to use invalid handle -1' error - Etchot - 2018-02-06

Sorry, what do you mean?


RE: 'Attempt to use invalid handle -1' error - Roman_V_M - 2018-02-06

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.


RE: 'Attempt to use invalid handle -1' error - Etchot - 2018-02-07

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.