Adding items to playlist "just-in-time" / "infinite scroll"

  Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
eddiewould Offline
Junior Member
Posts: 11
Joined: Jun 2016
Reputation: 0
Post: #1
Hi,

I'm writing a plugin for a source (of audio files) that is effectively infinite. I don't want to try and populate the whole playlist, but rather I'd like to populate a bit - and when the end of the playlist is reached, automatically populate it with a bit more.

In fact an upcoming "playlist" is more of a nice to have really - I'd settle for simply responding to the play/next/stop buttons.

So for example user starts my plugin playing, reaches end of file - kodi player asks my plugin for the next file and so on. Or if user presses the "next" button, kodi asks my plugin for the next file also.

Is this possible to achieve? I've experimented with subclassing the xbmc.Player and hooking into onPlayBackStarted/onPlayBackEnded as well as play/playnext but I can't seem to achieve what I want. Are there any examples of plugins that do this already?

Note that I don't expect "shuffle" to do anything meaningful, nor do I expect Kodi to be able to know how many items are available for play / what the total duration is etc.


Cheers,
Eddie
(This post was last modified: 2017-04-19 14:54 by eddiewould.)
find quote
ConfusedTA Offline
Fan
Posts: 300
Joined: Sep 2012
Reputation: 9
Location: England
Post: #2
Party Mode seems to do just this - a small playlist which continually updates to maintain X items.
find quote
Lunatixz Offline
Skilled Python Coder
Posts: 5,081
Joined: May 2011
Reputation: 155
Location: NYC
Post: #3
(2017-04-19 09:01)eddiewould Wrote:  Hi,

I'm writing a plugin for a source (of audio files) that is effectively infinite. I don't want to try and populate the whole playlist, but rather I'd like to populate a bit - and when the end of the playlist is reached, automatically populate it with a bit more.

In fact an upcoming "playlist" is more of a nice to have really - I'd settle for simply responding to the play/next/stop buttons.

So for example user starts my plugin playing, reaches end of file - kodi player asks my plugin for the next file and so on. Or if user presses the "next" button, kodi asks my plugin for the next file also.

Is this possible to achieve? I've experimented with subclassing the xbmc.Player and hooking into onPlayBackStarted/onPlayBackEnded as well as play/playnext but I can't seem to achieve what I want. Are there any examples of plugins that do this already?

Note that I don't expect "shuffle" to do anything meaningful, nor do I expect Kodi to be able to know how many items are available for play / what the total duration is etc.


Cheers,
Eddie


+1 Party Mode, but if you still want to write your script. I would create a threaded loop that compares the playlist position to the playlist size. When the position is approaching the end I'd start filling X amount of times.

Info can be found below, for specific help post here and i'll assist you.
Python_development (wiki)
https://codedocs.xyz/xbmc/xbmc/group__py..._list.html
(This post was last modified: 2017-04-19 16:53 by Lunatixz.)
find quote
eddiewould Offline
Junior Member
Posts: 11
Joined: Jun 2016
Reputation: 0
Post: #4
I've had a look into party mode - I don't think it will do what I want. From what I can tell it's geared around finding/filtering items from the _local_ library via a xsp file.

So long as I only *add* to the playlist, my add-on works fine. However I was worried that if left running for too long the playlist could eventually become very long. Hence why my add-on tries to prune (already played) items from the beginning of the playlist.

The actual pruning works fine, however I eventually get the error "Can't find a next item to play".

Here's what appears to be going on:

First step

Code:
=>1) A
  2) B
  3) C

3 items in playlist, playlist shows as playing song "A", Kodi is actually playing song "A". So far so good.

Second step (after pressing next). My addon removes the first item in the playlist and adds an item to the end of the playlist

Code:
1) B
=>2) C
  3) D

3 items in playlist, playlist shows as playing song "C", Kodi is actually playing song B. You can see where this is going...

Third step (after pressing next a second time)

Code:
1) C
  2) D
=>3) E

3 items in the playlist, playlist shows as playing song "E", Kodi is actually playing song "D".

If I try to skip again I see the "Can't find a next item to play" error message (which makes sense, because Kodi thinks it's at the end of the playlist).


See screenshots for a more visual explanation:

http://imgur.com/DbvnYYF
http://imgur.com/8PxLSYS
http://imgur.com/F9U6kDL
(This post was last modified: 2017-04-20 01:43 by eddiewould.)
find quote
rmrector Offline
Donor
Posts: 156
Joined: Sep 2010
Reputation: 14
Post: #5
The JSON-RPC method "Playlist.Remove" properly keeps focus when removing a previous item, give that a try. The Python Playlist object works fine for other methods I've needed, though.
(This post was last modified: 2017-04-20 05:35 by rmrector.)
find quote