Easiest way to determine when playlist finished (JSON-RPC "onStop" notification?)
#1
I have a script which generates a playlist and then plays it. This is all done through JSON-RPC.

I need to then resume the script once the playlist has stopped (either because it reaches the end or the user has pressed stop).

If I open a telnet session on port 9090 I can see the JSON-RPC notification "onStop" is triggered. Is there any way to capture this from within a python script?

If that's not possible, is there another appropriate way to do this? I could probably do something like check for active players on a loop, but this would seem to require a large number of repeated JSON requests.

I'm running nightly version from 26/11/11.


EDIT:
It also looks like the OnStop notification is triggered between playlist items - so this may not be the best way.

Any tips greatly appreciated.

el_P
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#2
Quick update - I've got an ugly system working in Python by opening a socket on port 9090 and listening to the notifications.

However, I can't easily determine the end of the notification and am instead just listening for the text "OnStop".

I've posted a question in the JSONRPC thread about the use of a break character at the end of each notification. Post is here.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#3
Could the player module may be of some assistence?

We use something like this in our script to listen if something is being played.
Quote:if not xbmc.Player().isPlaying():

http://passion-xbmc.org/gros_fichiers/XB...tml#Player

EDIT:
Nevermind just read you edit in the OP
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#4
Machine-Sanctum Wrote:Could the player module may be of some assistence?

We use something like this in our script to listen if something is being played.


http://passion-xbmc.org/gros_fichiers/XB...tml#Player

EDIT:
Nevermind just read you edit in the OP

That was what I had hoped would work as it seems a far simpler solution than opening a socket and parsing a JSON notification.

I might try again to see if I can get it working.

If not, there's a solution to getting the JSON notifications here.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#5
Yes - the same problem arises the player "stops" between playlist items. Therefore using JSON or isPlaying makes no difference (other than the latter is far simpler!).

I'll just need to do a quick check to see that the player doesn't resume straightaway.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#6
el_Paraguayo Wrote:Yes - the same problem arises the player "stops" between playlist items. Therefore using JSON or isPlaying makes no difference (other than the latter is far simpler!).

I'll just need to do a quick check to see that the player doesn't resume straightaway.

Maybe something like this (just a mokup code)
Code:
if playerstop:
    sleep(5)
    if playerstop:
         continue...
    else:
          redo loop

it is not nice but it should work i think.
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#7
Yeah, it will need to be something like that, but I'm hoping to avoid "sleep(x)" as much as possible so as to keep the user experience as seemless as I can.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#8
Hi,

just create a custom class of player and use event function

PHP Code:
import xbmc

class XBMCPlayerxbmc.Player ):
    
""" Subclass of XBMC Player class.
        Overrides onplayback events, for custom actions.
    """
    
def __init__self, *args ):
        
pass

    def onPlayBackStarted
self ):
        
# Will be called when xbmc starts playing a file
        
xbmc.log"Playlist started" )

    
def onPlayBackEndedself ):
        
# Will be called when xbmc stops playing a file
        
xbmc.log"End of Playlist" )

    
def onPlayBackStoppedself ):
        
# Will be called when user stops xbmc playing a file
        
xbmc.log"playlist Stopped" )


player XBMCPlayer()
player.play() 
For my bad English, sorry. I am French Canadian.
Admin @ Passion-XBMC.org
Reply
#9
Thanks Frostbox.

One question, if I've built up a playlist with JSONRPC how can I use the Player() to start playing this playlist?

player.play() doesn't trigger it.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#10
el_Paraguayo Wrote:Thanks Frostbox.

One question, if I've built up a playlist with JSONRPC how can I use the Player() to start playing this playlist?

player.play() doesn't trigger it.

You need to specify the playlist. (audio or video)
Code:
xbmc.Player.play( xbmc.PlayList( xbmc.PLAYLIST_VIDEO ) )
Code:
xbmc.Player.play( xbmc.PlayList( xbmc.PLAYLIST_MUSIC ) )

in place of the xbmc.PLAYLIST_MUSIC you can use an integer of 0 and 1 for xbmc.PLAYLIST_VIDEO.
Reply
#11
Thanks giftie. That got the video playlist playing.

However, none of the events in the class are being triggered (no log messages and custom notifications that I added).

I initialised the player at the very start of the script and then run the play command once the playlist has been built.

I have a separate working solution by doing
PHP Code:
while xbmc.Player().isPlaying():
    while 
xbmc.Player().isPlaying():
      
time.sleep(1)
    
time.sleep(0.5
but it still feels ugly. I need the nested loops as a single one will be triggered between playlist items, but the second shouldn't be triggered as the next playlist item will be triggered almost immediately.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#12
I use something similar in Cinema Experience, to keep track of Playback(Paused, resumed or stopped) as well as keeping track of the playlist position(for the home automation triggering)

el_Paraguayo Wrote:Thanks giftie. That got the video playlist playing.

However, none of the events in the class are being triggered (no log messages and custom notifications that I added).

I initialised the player at the very start of the script and then run the play command once the playlist has been built.

I have a separate working solution by doing
PHP Code:
while xbmc.Player().isPlaying():
    while 
xbmc.Player().isPlaying():
      
time.sleep(1)
    
time.sleep(0.5
but it still feels ugly. I need the nested loops as a single one will be triggered between playlist items, but the second shouldn't be triggered as the next playlist item will be triggered almost immediately.
Reply

Logout Mark Read Team Forum Stats Members Help
Easiest way to determine when playlist finished (JSON-RPC "onStop" notification?)0