setResolvedUrl: what does it do ?

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
N3MIS15 Offline
Donor
Posts: 505
Joined: Jul 2010
Reputation: 13
Location: Melbourne, VIC
Post: #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: all-fanart.jpg]
find quote
realtebo Offline
Senior Member
Posts: 164
Joined: Apr 2013
Reputation: 0
Post: #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: jpk9.jpg]

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 ?
(This post was last modified: 2013-12-13 11:05 by realtebo.)
find quote
realtebo Offline
Senior Member
Posts: 164
Joined: Apr 2013
Reputation: 0
Post: #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)
find quote
realtebo Offline
Senior Member
Posts: 164
Joined: Apr 2013
Reputation: 0
Post: #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.
find quote
learningit Offline
Senior Member
Posts: 250
Joined: Aug 2012
Reputation: 8
Post: #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')

Link to my t1m/learningit XBMC Addons: [Image: HLVT8d8.png]
find quote
Post Reply