Player.SetSubtitle issues when using an index for the "subtitle" parameter
#1
Part 1:

I'm doing some work with subtitles using JSON in Windows Kodi 19.3 and have run across some strange problems. My test files for this thread are .mkv files with embeded "S_TEXT/UTF8" subs per MediaInfo. I'm able to switch between them using Player.SetSubtitle:

https://kodi.wiki/view/JSON-RPC_API/v12#...etSubtitle

However, when subs are off, and I turn them on, it takes about 10 seconds for them to appear. When I turn them off, they disappear for about 10 seconds and then come back on. During this time, if I use the OSD to inspect subtitles, "Enable subtitles" is toggled on the whole time, and it never toggles off after I've turned off subtitles. OTOH, when I use the "showsubtitles" action, they go on and off immediately, and the correct state is reflected in "Enable subtitles". I also get the subtitles notification when I use "showsubtitles", which I don't get when I use SetSubtitle. (The notification absence may be expected. I haven't yet investigated it.)

My commands look like the following, and they're formatted to be run from Windows cmd. They all return "OK" results immediately after being run.

1. Turn on subtitles
Code:
curl -s --data-binary "{\"jsonrpc\":\"2.0\", \"method\":\"Player.SetSubtitle\", \"params\": {\"subtitle\": 0, \"enable\": true, \"playerid\": 1 }, \"id\": 1}" -H "content-type: application/json;" http://myip/jsonrpc

2. Turn off subtitles
Code:
curl -s --data-binary "{\"jsonrpc\":\"2.0\", \"method\":\"Player.SetSubtitle\", \"params\": {\"subtitle\": 0, \"enable\": false, \"playerid\": 1 }, \"id\": 1}" -H "content-type: application/json;" http://myip/jsonrpc

Part 2:

After discovering that "on" and "off" are legal values for the "subtitle" parameter, I tried getting rid of the "enable" parameter and running two Player.SetSubtitle commands in a row, the first one with a sub index, the second with "on" or "off", e.g.

1. Turn on subtitles
Code:
curl -s --data-binary "{\"jsonrpc\":\"2.0\", \"method\":\"Player.SetSubtitle\", \"params\": {\"subtitle\": 0, \"playerid\": 1 }, \"id\": 1}" -H "content-type: application/json;" http://myip/jsonrpc
curl -s --data-binary "{\"jsonrpc\":\"2.0\", \"method\":\"Player.SetSubtitle\", \"params\": {\"subtitle\": \"on\", \"playerid\": 1 }, \"id\": 1}" -H "content-type: application/json;" http://myip/jsonrpc

2. Turn off subtitles
Code:
curl -s --data-binary "{\"jsonrpc\":\"2.0\", \"method\":\"Player.SetSubtitle\", \"params\": {\"subtitle\": 0, \"playerid\": 1 }, \"id\": 1}" -H "content-type: application/json;" http://myip/jsonrpc
curl -s --data-binary "{\"jsonrpc\":\"2.0\", \"method\":\"Player.SetSubtitle\", \"params\": {\"subtitle\": \"off\", \"playerid\": 1 }, \"id\": 1}" -H "content-type: application/json;" http://myip/jsonrpc

This fixes the weird behavior I experienced with turning subs off, but I still get the 10 second delay after turning them on.

Conclusions:

1. It seems there is a 10 second delay before subtitles can be shown after calling Player.SetSubtitle with an index for its "subtitle" parameter. However, if I immediately do a skip-back, subs are shown immediately.
2. I'm not sure what the Player.SetSubtitle "enable" parameter is for. It doesn't help the delay when set to "true", and it causes the weird behavior described in Part 1 when set to "false" and a second call with "subtitle" set to "off" isn't made.

Question:

How do I get rid of the 10 second delay for displaying subtitles after using an index for the Player.SetSubtitle "subtitle" parameter?
Reply
#2
When subtitles are enabled, specifically the one with index 0 for this example, running the JSON equivalent given in my OP for Player.SetSubtitle(subtitle = 0) at the command line causes the subtitles to disappear immediately from the screen, and then 10 seconds later, they reappear. I can do this repeatedly, and the behavior is the same every time. I traced through the source code far enough to determine that Kodi destroys the current subtitle stream and creates a new one, even if the indexes are the same. I haven't found what actually causes them to appear on the screen, but whatever it is, it's taking it 10 seconds to notice and show them. I can make them appear immediately if, say, I do a Seek(-1). Unfortunately, Seek(0) doesn't have this effect. Is there any no-op I can use instead of Seek to force the video player to display the subs immediately after I switch between them?

I'm interested in this because I'm implementing more intelligent handling of subtitle toggling in Autohotkey for files containing forced subtitles, which I've talked about before:

https://forum.kodi.tv/showthread.php?tid...pid3003765

It's good I figured out how to avoid the "display delay" when there aren't any forced subs (i.e. don't SetSubtitle(index) when not changing the index), but the delay makes toggling subs suboptimal when there are both forced and normal subs. My "what did he say" function works fine because it immediately seeks backward, which forces the sync of the video with the newly set main subs, but then when it times out and switches from main subs back to forced, there's that 10 second delay before the forced ones start to appear again. The delay also occurs when I simply toggle subs when both forced and normal subs are present, because I'm switching between the two of them.
Reply

Logout Mark Read Team Forum Stats Members Help
Player.SetSubtitle issues when using an index for the "subtitle" parameter0