Correct way to play a DirectoryItem
#1
Suppose I have a addon that generates some list of e.g. videos. When the user selects a video from the list I want that video to play. Can I get XBMC to do this automatically or does the code in my plugin have to do it?

For example, suppose my addon generates a list with just one item:

Code:
listItem = xbmcgui.ListItem("Terminator")
xbmcplugin.addDirectoryItem(_thisPlugin,"C:\\Videos\\Terminator.avi", listItem)

Experiment shows that when the user selects this item nothing happens so I'm obviously doing this wrong. Is the correct method to do something like:

Code:
xbmcplugin.addDirectoryItem(_thisPlugin, "plugin://plugin.script.myplugin?terminator", listItem)

then have my addon check the command, "terminator", and call xbmc.player.play?

JR
Reply
#2
The first is just fine. Check your Debug Log to see whether there's anything interesting when you click "The Terminator".

Cheers,
Jonathan
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
#3
Aha, thanks. Armed with that clue I was able to track down the real bug, which was that I'd copied and pasted a previous addon.xml and left the <provides> tag set to "executable". Doh :-)

JR
Reply
#4
i have to second that.

doing my first steps in developing a plugin, i also want to play a file and it does not work...

i used the code from the wiki example:

Code:
def addLink(name,url,iconimage):
        ok=True
        liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
        liz.setInfo( type="Video", infoLabels={ "Title": name } )
        ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz)
        return ok
i call that function with
Code:
addLink(test,'/home/test.avi','')
(the file exists, i checked that.)

unfortunately, no playback. also the log is kinda quiet:
http://pastebin.com/XuGu3YEu

as far as i got it, i only need a ressource.xml if i want to have plugin setting? well, this is not the case...

can anyone help me? Wink
Reply
#5
no need it's just if you need settings.

show more of your code, is anything is displayed at this stage ?
Reply
#6
well, it is not really more code:

Code:
import urllib,re,xbmcplugin,xbmcgui,os, sys

def CATEGORIES(test):
        #addDir(test,'',1,'')
        #addDir(test,'',1,'')
        addLink(test,'/home/Serenity.avi','')

def addLink(name,url,iconimage):
        ok=True
        liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
        liz.setInfo( type="Video", infoLabels={ "Title": name } )
        ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz)
        return ok
        
CATEGORIES("test string")

xbmcplugin.endOfDirectory(int(sys.argv[1]))

edit:
my current workings:

Code:
import urllib,re,xbmcplugin,xbmcgui,os,sys
from xml.dom.minidom import parse

__language__ = xbmc.Language( os.getcwd() ).getLocalizedString

def getResults(film):
    notWantedKeywords = ["720p", "1080p", "Bluray", "Blueray"]
    unwantedKeywordFound = 0
    found = 0
    
    film  = film.replace(" ", "+")
    filmUrl = "http://search.student.utwente.nl/api/search?q=" + film + "&page=0&dirsonly=yes&n=500"
    try:
        feed = urllib.urlopen(filmUrl)
        dom = parse(feed)
        #check through all the <result>    
        for node in dom.getElementsByTagName('result'):
            #only take those which are online!
            if node.getElementsByTagName('online')[0].firstChild.nodeValue == 'yes':
                # we dont want bluray or any orther HD movie, the xbox cannot play it!
                for keyword in notWantedKeywords:
                    if node.getElementsByTagName('full_path')[0].firstChild.nodeValue.find(keyword) != -1:
                        unwantedKeywordFound = 1
                # okay, everything seems clear, now lets get rid of the directories, we only want the files!        
                if unwantedKeywordFound == 0:      
                    # check if there is a file ending
                    #if node.getElementsByTagName('name')[0].firstChild.nodeValue[len(node.getElementsByTagName('name')[0].firstChild.nodeValue) - 4] == ".":
                    addDir(node.getElementsByTagName('name')[0].firstChild.nodeValue, node.getElementsByTagName('full_path')[0].firstChild.nodeValue,1, '')
                    found = 1
                unwantedKeywordFound = 0;
        if found != 1:
            message("nothing found!")        
    except Exception:
        message("Could not reach CampusSearch!")

#search for something
def GUIEditExportName(name):
    exit = True
    while (exit):
        kb = xbmc.Keyboard('default', 'heading', True)
        kb.setDefault(name)
        kb.setHeading(__language__(33223))
        kb.setHiddenInput(False)
        kb.doModal()
        if (kb.isConfirmed()):
            name_confirmed  = kb.getText()
            name = name_confirmed
            exit = False
            #name_correct = name_confirmed.count(' ')
            #if (name_correct):
            #   GUIInfo(2,__language__(33224))
            #else:
            #     name = name_confirmed
            #     exit = False
        else:
            GUIInfo(2,__language__(33225))
    return(name)
    
def message(text):
    dialog = xbmcgui.Dialog()
    dialog.ok("Error", text)

def addLink(name,url,iconimage):
        ok=True
        liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
        liz.setInfo( type="Video", infoLabels={ "Title": name } )
        ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz)
        return ok


def addDir(name,url,mode,iconimage):
        ok=True
        liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
        liz.setInfo( type="Video", infoLabels={ "Title": name } )
        ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz,isFolder=True)
        return ok

requestedMovie = ""
requestedMovie = GUIEditExportName(requestedMovie)
getResults(requestedMovie)

xbmcplugin.endOfDirectory(int(sys.argv[1]))

it nearly works. it lists all the directory with the found movies, but as soon as i enter them i cannot see any files - although they are there. they are just not displayed. i think im doing a basic error, but i dont know which one.
Reply

Logout Mark Read Team Forum Stats Members Help
Correct way to play a DirectoryItem0