First Plugin Development, need help with code
#1
Hey folks,

Im just working on my first plugin (and I am enjoying it a lot Laugh).

I'm stuck at some point and require some help from you guys.


Here is what I wanna do:

I have a long list of urls, which is displayed to the user. If you follow one of those urls in your browser, you can find a non-generic link to an audio stream.

That is why I want to parse the list, and present it to the user in a plugin. If the user selects an item, I want the plugin to parse the stream adress and directly play it. I stole this code from the moviemaze addon:

Code:
## Here comes the of the .ram file refering to the resolved id
        urlnew = 'http://mouth.betalounge.com/ramgen/lounge/2010/101002_soulalldayer_de.rm?start=0&end=0'
## Play this file

        liz=xbmcgui.ListItem('test', iconImage="DefaultVideo.png", thumbnailImage="DefaultVideo.png")
        liz.setInfo( type="Audio", infoLabels={ "Title": 'Test' } )
        
        Player = xbmc.Player(xbmc.PLAYER_CORE_AUTO)
        Player.play(urlnew, liz)
        xbmc.executebuiltin('Container.Refresh')

Unfortunately this isn't working. I get no error whatsoever, xbmc just starts 'Working' and then nothing happens. No entry in the debug log.

Is my logic correct? I really hope someone can help me.

Best wishes,

Axel
Reply
#2
If you're writing a plugin there is no need to actually call the player etc. You just provide directory listings to XBMC. I use something like this:

Code:
def addLink(self, name,url):
    liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage='')
    liz.setInfo( type="Video", infoLabels={ "Title": name } )
    liz.setProperty("IsPlayable" , "true")
    xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz)

to add playable items to the listings in you end the listing with something like this:

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

Your setup looks more like a script.
Reply
#3
Hey magnetism,

thanks for your answer. I know already what you explained to me.

There is a reason for my approach: I don't want to parse every stream url when displaying the url list. This would mean to open 2 websites for every entry and therefore very long loading times for the plugin
Reply
#4
I don't understand what you mean. The point is to not call player.play, but to return a listing of items to display in the xmbc browser. If you don't want to parse a certain URL until it is selected, then you can use a link to your own plugin and use

xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, xbmcgui.ListItem(path = testfile)) #@UndefinedVariable


to resolve it to the proper URL once required.
Reply
#5
Allright, thanks for the hint! I will try this!
Reply
#6
This is the definition BTW.

Code:
def setResolvedUrl(*args):
    """setResolvedUrl(handle, succeeded, listitem) -- Callback
     function to tell XBMC that the file plugin has been resolved to a url
    
    handle           : integer - handle the plugin was started with.
    succeeded        : bool - True=script completed
     successfully/False=Script did not.
    listitem         : ListItem - item the file plugin resolved to for
     playback.
    
    *Note, You can use the above as keywords for arguments and
     skip certain optional arguments.
    Once you use a keyword, all following arguments require the
     keyword.
    
    example:
    - xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem)
    """

There is a handy addon that allows you the generate this documentation from a running instance of XBMC (and one which provides bindings for Pydev-eclipse, which is what I use)

Very useful.
Reply
#7
Sorry Mate, I am obviously too stupid for that.

I know the definition, but I cannot really follow the logic that is presented here....

I call your code, after a listitem with the url sys.argv[0]+'?mode=1' has been selected, by using the mode-value like this:

Code:
if mode != 1:
        showlinks()
else:        
        playlink()

playlink() looks like this:

Code:
def playlink():

## Here comes the of the .ram file refering to the resolved id
urlnew = 'http://mouth.betalounge.com/ramgen/lounge/2010/101002_soulalldayer_de.rm?start=0&end=0'

xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, xbmcgui.ListItem(path = urlnew))

And nothing happens Sad. Can you please provide me the correct code?
Reply
#8
What does showLinks() look like? If I'm not mistaken, the links should have the isPlayable propery set to true.
Reply
#9
Spaggi Wrote:Sorry Mate, I am obviously too stupid for that.

I know the definition, but I cannot really follow the logic that is presented here....

I call your code, after a listitem with the url sys.argv[0]+'?mode=1' has been selected, by using the mode-value like this:

Code:
if mode != 1:
        showlinks()
else:        
        playlink()

playlink() looks like this:

Code:
def playlink():

## Here comes the of the .ram file refering to the resolved id
urlnew = 'http://mouth.betalounge.com/ramgen/lounge/2010/101002_soulalldayer_de.rm?start=0&end=0'

xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, xbmcgui.ListItem(path = urlnew))

And nothing happens Sad. Can you please provide me the correct code?

are you just wanting to play "urlnew"? if so, below will do it

Code:
def playlink():

## Here comes the of the .ram file refering to the resolved id
urlnew = 'http://mouth.betalounge.com/ramgen/lounge/2010/101002_soulalldayer_de.rm?start=0&end=0'


xbmc.Player().play(urlnew)
Reply
#10
showlinks() just calls this function:

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

I cannot see the isPlayable attribute in the addDirectoryItem Function
Reply
#11
liz.setProperty("IsPlayable" , "true")
Reply
#12
This looks really promising. It seem that right now the page stopped working, but it seems to be looking for the stream. Thanks guys, I would have never found that without you!
Reply

Logout Mark Read Team Forum Stats Members Help
First Plugin Development, need help with code0