setResolvedUrl: what does it do ?
#16
If you have enough information to populate a list (title, thumbnail and so on) but grabbing the video url requires extra digging this is where you should use setResolvedUrl.
So you populate your list based on initial scrape then when the user clicks a list item (and only then) you point your list item to a function to grab the "resolved" url of the video file and tell xbmc it has been found so it can play the "resolved" url rather than a call back to the plugin.

As previously stated, it saves multiple unnecessary requests by only grabbing the data when the user requests it.
Image
Reply
#17
Now, I don't understand again ...

In my addon I've a 'Cd rom track list' grabbed, so I've a list of 135 mp3 in a specific case.

When user click on Cd title, I populate the list using addItem/endDirectory technique.
A progress bar appear, it looks like xbmc is doing osmething with every single mp3 link (isPlayable = true).

Image

So now I'm reading this thread and I've a dubt about what I'm doing.

See my code:

Code:
def showAudioJson(json_url):

    language        = jw_config.language
    language_code   = jw_config.const[language]["lang_code"]
    json_url        = "http://www.jw.org" + json_url
    json            = jw_common.loadJsonFromUrl(url = json_url, ajax = False)
    cover_image     = json["pubImage"]["url"]
    
    for mp3 in json["files"][language_code]["MP3"]:
        url     = mp3["file"]["url"]
        title   = jw_common.cleanUpText(mp3["title"])

        # Skip 'zip' files
        if mp3["mimetype"] != "audio/mpeg":
            continue;

        listItem = xbmcgui.ListItem(
            label           = title,
            thumbnailImage  = cover_image
        )

        listItem.setInfo(
            type        = 'Music',
            infoLabels  = {'Title': title }
        )

        xbmcplugin.addDirectoryItem(
            handle      = jw_config.plugin_pid,
            url         = url,
            listitem    = listItem,
            isFolder    = False
        )  

    # If there is only one audio item in the json, I start playing
    # Otherwise the standard item list will be generated
    if len(json["files"][language_code]["MP3"]) == 1 :

        xbmc.Player().play(item=url, listitem=listItem)
        return;


    xbmcplugin.endOfDirectory(handle=jw_config.plugin_pid)

I really really really cannot understand how to modify this code to use setResolvedUrl and which benefit I can take from it.
Can you help me ?
Reply
#18
Ok, I tried this, but it shows only ONE item, even If there are 135 mp3 in json["files"][language_code]["MP3"]:

No errors in log file. Why ?

Code:
for mp3 in json["files"][language_code]["MP3"]:

        params = {
            "content_type"  : "audio",
            "mode"          : "play_mp3",
            "file_url"      : mp3["file"]["url"]
        }

        #url     = mp3["file"]["url"]
        url = jw_config.plugin_name + '?' + urllib.urlencode(params)    

        title   = jw_common.cleanUpText(mp3["title"])

        # Skip 'zip' files
        if mp3["mimetype"] != "audio/mpeg":
            continue;

        listItem = xbmcgui.ListItem(
            label           = title,
            thumbnailImage  = cover_image
        )

        listItem.setInfo(
            type        = 'Music',
            infoLabels  = {'Title': title }
        )

        listItem.setProperty("IsPlayable","true")

        xbmcplugin.addDirectoryItem(
            handle      = jw_config.plugin_pid,
            url         = url,
            listitem    = listItem,
            isFolder    = False
        )  

        xbmcplugin.setResolvedUrl(handle=jw_config.plugin_pid, succeeded=True, listitem=listItem)

    # If there is only one audio item in the json, I start playing
    # Otherwise the standard item list will be generated
    if len(json["files"][language_code]["MP3"]) == 1 :

        xbmc.Player().play(item=url, listitem=listItem)
        return;


    xbmcplugin.endOfDirectory(handle=jw_config.plugin_pid)
Reply
#19
YES YES YES !! Ok .., I found how to use setResolvedUrl ... and addon now is very very very fast !!!!

The list uses for link not a simple mp3 but a new mode "play_mp3".

Code:
for mp3 in json["files"][language_code]["MP3"]:

        params = {
            "content_type"  : "audio",
            "mode"          : "play_mp3",
            "file_url"      : mp3["file"]["url"]
        }

        #url     = mp3["file"]["url"]
        url = jw_config.plugin_name + '?' + urllib.urlencode(params)    

        title   = jw_common.cleanUpText(mp3["title"])

        # Skip 'zip' files
        if mp3["mimetype"] != "audio/mpeg":
            continue;

        listItem = xbmcgui.ListItem(
            label           = title,
            thumbnailImage  = cover_image
        )

        listItem.setInfo(
            type        = 'Music',
            infoLabels  = {'Title': title }
        )

        listItem.setProperty("IsPlayable","true")

        xbmcplugin.addDirectoryItem(
            handle      = jw_config.plugin_pid,
            url         = url,
            listitem    = listItem,
            isFolder    = False
        )  

    # If there is only one audio item in the json, I start playing
    # Otherwise the standard item list will be generated
    if len(json["files"][language_code]["MP3"]) == 1 :

        xbmc.Player().play(item=url, listitem=listItem)
        return;


    xbmcplugin.endOfDirectory(handle=jw_config.plugin_pid)

... then when addon.py detect this mode uses the following code to start playing:

Code:
def playMp3(url):
    item = xbmcgui.ListItem(path=url)
    xbmcplugin.setResolvedUrl(handle=jw_config.plugin_pid, succeeded=True, listitem=item)

Now I'll do a complete retesting of every part of code that uses the first function to be sure all is working.
Reply
#20
(2013-12-13, 11:53)realtebo Wrote: ... then when addon.py detect this mode uses the following code to start playing:

Code:
def playMp3(url):
    item = xbmcgui.ListItem(path=url)
    xbmcplugin.setResolvedUrl(handle=jw_config.plugin_pid, succeeded=True, listitem=item)

Now I'll do a complete retesting of every part of code that uses the first function to be sure all is working.

yes that's one way to use it - you might also want to consider setting the ListItem property for the mimetype when you add it to the directory as well. It can speed things up under some circumstances. Something like:

item.setProperty('mimetype', 'audio/mpeg')
Reply

Logout Mark Read Team Forum Stats Members Help
setResolvedUrl: what does it do ?0