Detecting playback ended for playlist ?
#1
I have an addon which has a service that monitors playback using the xbmc.player class with the onPlayBackEnded,  etc.  methods to monitor what the Kodi player is doing.  I have another part of the addon which dynamically creates a playlist and plays it. Everything works fine but I am trying to, in the service part of the addon, to detect when the playlist has completed playback.  Kodi doesn't have an xbmc.player  method like onPlayListEnded  or similar so when the playlist is playing I get onPlayBackEnded followed by onPlayBackStarted.

I am trying to find a simple but reliable solution to determine when the playlist has ended vs. a normal file.  Note that the addon also plays many single files vs. the dynamic playlists.  One solution I thought of is when the dynamic playlist is crated and starts playing, set an addon setting variable with the number of items in the playlist +1 .   Then when onPlayBackEnded is reached, decrement the addon setting variable by 1 and when the addon setting variable value reaches 1 when onPlayBackEnded I'll know it just played the last item in the playlist.  Then I do something and set the value to 0. 

This should work but it isn't elegant and I am sure there is likely a better option.  I was thinking possibly of an JSON RPC call to check the position in the playlist onPlayBackEnded but when playback ends after the last item, the playlist is destroyed.  

Open to suggestions.  I would think detecting the end of a playlist vs. the end of an individual file playback is something others have needed in other addons vs.this being something really unique.

Thanks in advance,

Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , CBC Sports, Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply
#2
not sure how synchronous the code runs but if it wont block any execution the simplest thing i can think of is a tracking variable

onPlaybackStarted set variable isPlaying=1

onPlaybackEnded
isPlaying=0
sleep(3)
if isPlaying=1:
#playlist continues
else:
#playlist ended


would depend on onPlaybackStarted to be able to set to 1 while the sleep is happening, pretty sure class events will be able to change variables during a sleep of a different execution thread
Reply
#3
(2023-05-22, 03:55)jepsizofye Wrote: not sure how synchronous the code runs but if it wont block any execution the simplest thing i can think of is a tracking variable

onPlaybackStarted set variable isPlaying=1

onPlaybackEnded
isPlaying=0
sleep(3)
if isPlaying=1:
#playlist continues
else:
#playlist ended


would depend on onPlaybackStarted to be able to set to 1 while the sleep is happening, pretty sure class events will be able to change variables during a sleep of a different execution thread

Thanks for the idea.  I already have a similar approach in the service portion of the addon to help monitor playback and update resume pointers and such.  This approach could work but I would still need to pass a value to the onPlaybackStarted method  so it knows that a playlist has started playing vs. a file.  Your approach would eliminate the  onPlayBackEnded calls as the playlist sequences through the files but at the end of both an individual file or a playlist would have the same result of onPlayBackEnded but I wouldn't know whether it was a file or playlist which ended.  That's what I am trying to distinguish.

However, on better news, I think I may not go down this road altogether.   The root cause of this is to ensure the resume and already played indicators in the skin get updated properly upon ending playback, which Kodi normally does by default, if the Kodi database is updated properly, which I do.  However, it doesn't appear to work properly on a playlist with the Confluence skin but does work fine with files in Confluence.  With the Estuary skin it works fine on both playlists and files.  I haven't tested other skins yet but plan to.  If it turns out just to be a bug with the Confluence skin and playlists,  I'll just leave it alone vs. trying to code around it.   

I am going to do some more testing.


Thanks,

Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , CBC Sports, Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply
#4
right on

i tried to find some functionality that mimics settimeout in javascript where it would be cancelable but it got a little bit too far fetched

basically have to create a thread that waits onPlaybackEnded and then close that thread onPlaybackStart, assuming playback starts quickly the thread would be closed before the sleep completed and then it wouldnt execute anything

if this is indeed a one-off issue with a skin then i would agree allow the skin dev to fix it
Reply
#5
(2023-05-22, 17:30)jepsizofye Wrote: right on

i tried to find some functionality that mimics settimeout in javascript where it would be cancelable but it got a little bit too far fetched

basically have to create a thread that waits onPlaybackEnded and then close that thread onPlaybackStart, assuming playback starts quickly the thread would be closed before the sleep completed and then it wouldnt execute anything

if this is indeed a one-off issue with a skin then i would agree allow the skin dev to fix it

After thinking about this a bit more and looking at my current addon code, I found a very elegant solution to the detecting playlist ending problem.  The playlist stop / ending that I am trying to detect will always have the same pattern play x number of movie trailers and then play the main movie.  onPlayBackStopped and onPlayBackEnded don't work by default because whether a trailer ends or the main movie ends they look the same.  The elegant part of this is that my addon al;ready detects whether a trailer or main movie is playing based upon the URL name (Mezzmo trailer and main movie URLs are different). 

So with this I simply set a hidden addon setting when the playlist playback starts (I have to pass between a service and main portions of the addon so a hidden setting is the easy way) and then when a main movie ends I detect whether the playlist setting is set.  If both conditions are true I know it is a playlist and take appropriate action.  When trailer playback ends / restarts during the playlist playback I just ignore the playback ending because it is a trailer vs. the main movie.  If the playlist format ever changes where there are multiple main movies this method won't work. 

Since this issue only appears with some skins, I added a setting to the addon so that the user can enable / disable this detection capability to do a container refresh after playing a playlist.

It feels like the right thing to do is a feature request for 2 new player class methods:     onPlayListStopped and onPlayListEnded or similar.  I am surprised oethers haven't run across the need to detect playlist playback actions.


Thanks,

Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , CBC Sports, Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply

Logout Mark Read Team Forum Stats Members Help
Detecting playback ended for playlist ?0