How to play an item instead of showing a list of items ?
#1
I've a BIG problem with my own plugin.

I show a list of video to the users.
This is ok

When user select a video, I show all available resolutions.
For example: 240p, 360p, 480p, etc...

I created a user preference setting to allow auto play at a specific video resolution.

So I can avoid a step to the users.
This is the step of the problems:

When I must show list of available res, I use a 'classic

Code:
xbmcplugin.addDirectoryItem(
            handle=jw_config.plugin_pid,
            url=url,
            listitem=listItem,
            isFolder=True
        )

But if I found the choosen video resolution, i use this

Code:
xbmc.Player().play(item=url_to_play, listitem=listItem)
return;

All is working on Frodo, but in Gotham the systm is expecting a endOfDirectory and so a warning jump to the screen with a (useless) message

"Remote sharing: Unable to connect to server"

I cannot understand why this issue on Gotham and not on Frodo. but I'm here to ask you how to workaround this problem... please help me!

I know it is not good to do a "Play" when xbmc expect a directory, so I ask you a method to avoid this.

I cannot detect video res of every single video at the stage of video listing, because this need to load and scan html from a different htnl page for every single video... it's extermely long for user to wait all of this time
Reply
#2
I am with almost the same trouble as you. I manage to get a list of videos but I still need to parse another URL before telling XBMC to play it.
My code runs ok on the XBMC installed on a Mac, but it crashes on a XBMC installed on the Raspberry Pi.

Since my code works on the mac. Here is the main code for you, check if it helps you in anyway:
Code:
(...)
def fetchUrl(url):
    req = urllib2.Request(url);
    response = urllib2.urlopen(req);
    data = response.read();
    response.close();
    return data;

def makeUrl(query = {}):
    return base_url + "?" + urllib.urlencode(query);

mode = args.get("mode", None);
xbmcplugin.setContent(addon_handle, 'movies');

if mode is None:
    index = fetchUrl(thenoite_urls['na_integra']);
    videos = json.loads(index);
    for video in videos["videos"]:
        li = xbmcgui.ListItem(video["title"], iconImage=video["thumbnail"])
        url = makeUrl({"mode" : "videourl", "play_video" : video_url.replace("$videoId", video["id"])});
        xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li, isFolder=True)

elif (mode[0] == "videourl"):
    iframe = fetchUrl(args.get("play_video")[0]);
    match = re.compile("window.mediaJson = (.+?);").findall(iframe);
    if match[0]:
        video = json.loads(match[0]);
        for deliveryRules in video["deliveryRules"]: # this is just me finding the video url
            if (deliveryRules["rule"]["ruleName"] == "r4"):
                for output in deliveryRules["outputList"]:
                    if (output["labelText"] == "480p"): # video url is on output["url"] variable now
                        listitem = xbmcgui.ListItem(video["title"]);
                        listitem.setArt({"thumb" : video["thumbnailList"][1]["url"]});
                        xbmc.Player().play(output["url"], listitem);

xbmcplugin.endOfDirectory(addon_handle)
Reply
#3
No idea if it's the correct way of doing it, only that it seems to work for me...

When I want to play an item (indeed, any time I want a script to handle what happens when a listitem is selected), I always pass in setResolvedURL with succeded=False:

Code:
xbmcplugin.setResolvedUrl( handle=int( sys.argv[1]), succeeded=False, listitem=xbmcgui.ListItem() )

and not return endOfDirectory. Seems to work OK, though I'm sure there's an official (and better!) way to do this Smile (And a recent bug in service.library.data.provider which caused albums not to play was caused because the endOfDirectory was passed, when the script was responsible for starting the media playing. Exiting the script before the endOfDirectory, and just calling the setResolvedUrl solved it).
Reply
#4
Calling setResolvedUrl() is what you want if you've passed back a listitem at a previous occasion and marked it as playable, but it still has a plugin:// URL. Your plugin will be called, and it's expected that you call setResolvedUrl(), feeding the correct URL back to XBMC for playback.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#5
So I've been using it wrong all this time. I wish I could say I'm suprised Wink

To be clear, if the script is taking care of playing the media rather than passing a url for Kodi to play - a live tv channel for example, which is far easier to start via json than the python api or xbmc url - we don't need to call endDirectoryItems or setResolvedUrl? We just call json to play the media, and return? (I vaguely remember issues doing this in the early days of skin shortcuts, but that's a long time ago)
Reply

Logout Mark Read Team Forum Stats Members Help
How to play an item instead of showing a list of items ?0