Detect and discard play-command
#1
Hello

How can I determine in a python addon whether the user wants to play a movie / wants to start the Player? The onPlayBackStarted(...) method is called too late and the onQueueNextItem(...) method does not work for me unfortunately...
I tried it like in this example:

Code:
import xbmc
import xbmcaddon

addon = xbmcaddon.Addon()

class test(xbmc.Player):
    def onQueueNextItem(self):
        xbmc.log(msg='Queue NextItem')
        xbmc.executebuiltin('Notification(Queue, NextItem)')

t = test()
while (not xbmc.abortRequested) and (addon.getSetting('service_enabled') == 'true'):
    xbmc.sleep(200)

del t

Dont know why but the method was not called when I put something in the queue?! Is something wrong with the code or is it a bug in 12.2?

I would need something like a onBeforePlay method or better a method to catch and discard the play-command if a (library) item is selected... It should also work if the mediasource is not available...

Do you have any ideas?
Thanks in advance
4



EDIT:
I have found now that the "onQueueNextItem" method is only called a few seconds before a Playlistitem is changed. Not when the Playlist is getting a new Item... Sorry... My mistakeBlush

Would something like a "onBeforePlay"- or "onLibraryItemSelectedToPlay"-method be a new candidate for a feture request for the xbmc.player-class?
Would it be possible to integrate this into XBMC?

Regards
4
Reply
#2
*push*
Reply
#3
IIRC, onQueueNextItem only gets triggered if the currently playing item is a playlist, not if its played directly.
I think your best bet is to try to "monkey patch" the play method:
Code:
class my_player(xbmc.player):
    def play(*args):
         do_something()
         xbmc.play(*args)
Reply
#4
I found that even testing for play was too slow even. In Cinema Experience I test for the Full Screen video. It usually works...

Code:
while ( not xbmc.abortRequested ):
    if int( xbmc.PlayList( xbmc.PLAYLIST_VIDEO ).size() ) > 0:
        while not int( xbmcgui.getCurrentWindowId() ) == 12005:
            xbmc.sleep( 100 )
            #log( 'Waiting for full screen video' )
            xbmc.Player().stop()
Reply
#5
Thank you for your responses.

@Bstrdsmkr
With your function I would have to call the play method... But I am looking more for the other way round. I would need to react to the "play-action" respectively the attempt to play the file...

@giftie
Nice workaround :thumbsup:
But the problem with this code is the playlist... The playlist will only be filled if the source is available...


I think I have to give you some more background information about the addon... The addon stores movies from the XBMC-library (from the Server/Nas) locally on the PC... You could use the local movies as usual in XBMC... All the needed functions already exists... But the main problem at the momment is a dialog to control the addon... I thought about a dialog that is shown if the user selects a movie in the library. The dialog would have different options to play the movie from the default source, from the local path etc...
The onPlayBackStarted-method is not useful if the source is not available (because of the "Movie does not exists - Delete?" - dialog)...

An other possible option could be a home-menu-item or a context menu item in the library-view to show the dialog... But for the context menu item there is no way known (for me) and the home-item is "to far away/not the nice way"... I would like to integrate the addon closer into xbmc...

Sorry... My english is a bit rustyBig GrinCool
Reply
#6
Hey mate sounds like you are trying to develop something I very badly want. Happy to help if you need it.

Have you looked at the menu that comes up when you try to watch a movie that has progress saved and it asks if you want to resume or watch from the beginning? That should have some sort if hook to allow you to intercept the play command?
Reply
#7
I think the only way to do what you want currently is to setup a custom player. It could even be a "stub" player that only does what you want and then conditionally starts playback in xbmc
Reply
#8
Quote:Happy to help if you need it.

Help is always welcome :thumbup:

Quote:Have you looked at the menu that comes up when you try to watch a movie that has progress saved and it asks if you want to resume or watch from the beginning? That should have some sort if hook to allow you to intercept the play command?

Maybe i didn't understand you but would it not be the same if you play it directly? This would only be a additional dialog with the same function?!

In the meantime i tried something like in this pseudocode

Code:
import xbmc
import xbmcgui

class test(xbmcgui.Window):
    def onInit(self):
        xbmc.executebuiltin('Notification(head,msg)')

    def onAction(self, Action):
        if Action == 'Play':
            Action = noop

if __name__ == '__main__':
    xbmc.executebuiltin('Notification(Addon, begin)')
    win = test(10025)

    # do nothing
    while (not xbmc.abortRequested):        
        xbmc.sleep(1000)

    del win
    xbmc.executebuiltin('Notification(Addon, end)')

Works not Big Grin


Quote:I think the only way to do what you want currently is to setup a custom player. It could even be a "stub" player that only does what you want and then conditionally starts playback in xbmc

Could you describe it a little closer?


I have also been thinking about to use the playercorefactory and to disable the internal player...
But I guess that would not make sense. On the one side I can not turn him off when I need him on the other side for the script to play the files... And i dont know if the "source check" would popup if the server is turned off...


I'm beginning to think that this addon is a hopeless ventureBig Grin Next time i start with the dialogSmile
Reply
#9
(2013-12-16, 20:27)4lb3rtO Wrote: Help is always welcome :thumbup:

OK I've been working at this for the past couple of days and have completed a script to make this work by adding a command to the context menu. Smile

http://forum.xbmc.org/showthread.php?tid=180588
Reply

Logout Mark Read Team Forum Stats Members Help
Detect and discard play-command0