Skip to content

fix: enable multi-segment playback via JSON-RPC#154

Open
maximilian-sh wants to merge 2 commits intos0faking:masterfrom
maximilian-sh:fix/playlist-playback-not-starting
Open

fix: enable multi-segment playback via JSON-RPC#154
maximilian-sh wants to merge 2 commits intos0faking:masterfrom
maximilian-sh:fix/playlist-playback-not-starting

Conversation

@maximilian-sh
Copy link
Copy Markdown

@maximilian-sh maximilian-sh commented Mar 11, 2026

Problem

Multi-segment episodes (e.g. ZIB 2 on ORF TVthek) add all segment URLs to a `PlayList` and previously called `Player().play(playlist)` directly. This caused intermittent crashes with two concurrent BusyDialogs — one opened by Kodi to resolve the plugin URL, one from `Player().play()`.

Fix

Call `setResolvedUrl(handle, False)` first to signal that the plugin URL is not directly playable and close the resolution context cleanly.

In GUI mode, the playlist player then handles everything automatically: it skips the unresolvable plugin URL at position 0 and plays the segments — same behaviour as before, no regression.

For JSON-RPC (`Player.Open` via external control like Kodi remotes or home automation), no playlist player is active after `setResolvedUrl` returns, so playback would silently stop. We detect this by recording `pre_size = playlist.size()` before adding tracks: in GUI mode Kodi always pre-inserts exactly 1 item (the plugin URL itself), so `pre_size == 1`. In JSON-RPC mode no item is pre-added, so `pre_size != 1` — we then start playback explicitly from position `pre_size` (the first newly added track). This also correctly handles the case where the global playlist has leftover items from a previous session.

Note

I put this together to fix JSON-RPC control of multi-segment content and it works correctly in both GUI and JSON-RPC testing. Happy to hear if there is a cleaner way to distinguish these two contexts.

Multi-segment episodes (e.g. ZIB 2) add all segment URLs to a playlist.
Previously Player().play(playlist) was called directly, which caused
intermittent crashes from two concurrent BusyDialogs — one opened by
Kodi to resolve the plugin URL, one from Player().play().

Instead, call setResolvedUrl(handle, False) to signal that the plugin
URL itself is not directly playable and close the resolution context
cleanly. In GUI mode, the playlist player then takes over: it skips the
unresolvable plugin URL at position 0 and plays the segments at 1..n
automatically, same as before.

For external JSON-RPC control (Player.Open), no playlist player is
active after setResolvedUrl returns, so playback would silently stop.
We detect this by checking whether playlist.size() == len(tracks):
if true, Kodi did not pre-insert the plugin URL at position 0, meaning
we are in a JSON-RPC context and need to start playback explicitly.

Note: the JSON-RPC detection via playlist size comparison is a heuristic
that works in testing but may not cover all edge cases — happy to hear
if there is a cleaner way to distinguish these two contexts.
@maximilian-sh maximilian-sh force-pushed the fix/playlist-playback-not-starting branch from f859f95 to 9925dd0 Compare March 12, 2026 00:48
@maximilian-sh maximilian-sh changed the title fix: playlist playback not starting for multi-segment episodes fix: enable multi-segment playback via JSON-RPC Mar 12, 2026
The previous playlist.size() == len(tracks) check failed when the global
video playlist had leftover items from a previous session, causing JSON-RPC
playback to silently do nothing.

In GUI mode Kodi always adds exactly 1 item (the plugin URL itself) to the
playlist before running the plugin, so pre_size is 1. In JSON-RPC mode no
item is pre-added, so pre_size is 0 or reflects leftover playlist state.
Using pre_size != 1 as the JSON-RPC guard is reliable regardless of prior
playlist contents, and startpos=pre_size correctly points to the first
newly added track.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant