Solved xbmc.Player().setSubtitles not working ?!?
#1
Hi All

I'm using 17.0-RC3 via osmc on my RPi2.

For some reason showing subtitles by the xbmc.Player().setSubtitles(filename) doesn't seem to work consistently on krypton (it did on kodi-16). My issue is specifically on the plugin.video.drnu addon, that don't show subtitles anymore. In the addon an url to the subtitles is found (every time, I have checked), which is then passed to xbmc.Player().setSubtitles after it is checked that player.isPlaying().

But still no subtitles shown or in the osd. If I in the addon add a line to download the file from the found url and save it locally I can choose that file after the video has started and that works every time. Even if I use setSubtitles with this local file it doesn't work...

I don't see anything in the logs about the setSubtitles command.

Any ideas to why it doesn't work? Anyone else with this issue?
Reply
#2
I made a trac about this about a year ago but there was no intrest, cant find it now Sad

but I can confirm this is broken on krypton
Reply
#3
Alright then trying to look a bit further into the code...

If I look at:
https://github.com/xbmc/xbmc/blob/8d4a5b...Player.cpp

the important part is:
Code:
void Player::setSubtitles(const char* cLine)
    {
      XBMC_TRACE;
      if (g_application.m_pPlayer->HasPlayer())
      {
        g_application.m_pPlayer->AddSubtitle(cLine);
      }
}

and looking a bit more around this file I see that many of the other functions use
Code:
if (!g_application.m_pPlayer->IsPlaying())
instead of
Code:
if (g_application.m_pPlayer->HasPlayer())

The only function I can see that returns something that I know I have when playing from the addon and that also use the HasPlayer() is the getAvailableAudioStreams() function.

Using this in the addon returns an empty list, when there should be one audio stream as I also can see in the gui... Is this the source of the problem then?

Is there a developer around that can comment on if HasPlayer() could be the source of why setsubtitles is not setting anything and also it seems to me that getAvailableAudioStreams() returns an empty list??
Reply
#4
this is what i tested and works fine:
Code:
xbmc.Player().setSubtitles('/home/ronie/15.srt')

in the Debug Log, this line shows up:
Quote:12:06:04.952 T:140712037353216 DEBUG: GetExternalStreamDetailsFromFilename - Language = '' / Name = '(External)' / Flag = '0' from /home/ronie/15.srt


if you're having python issues, please alway provide the exact code you're using and a Debug Log ;-)
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#5
python code:
Code:
xbmc.Player().setSubtitles('/home/osmc/temp/temp.srt')

As stated earlier what I do for now while testing is downloading the subtitle file in the script after it has found the url and save it to /home/osmc/temp/temp.srt. In the debug log I also see this when the playback is starting by the watchdog line:
Code:
12:16:38.875 T:1477432304   DEBUG: [service.watchdog] [event] <modified> <u'/home/osmc/temp/temp.srt'>

but that is the only place with anything with "srt" in my log....

cut out of log from start of playback in script and to push of stop video:
http://ge.tt/1gRQdQi2
Reply
#6
so if i understand it correctly, it is the plugin.video.drnu addon that is making the xbmc.Player().setSubtitles() call?

looking at the log, the plugin exits long before playback of the video starts:
Code:
12:16:39.341 T:1501029360    INFO: CPythonInvoker(65, /home/osmc/.kodi/addons/plugin.video.drnu/addon.py): script successfully run
12:16:49.742 T:1958568944   DEBUG: CAnnouncementManager - Announcement: OnPlay from xbmc

so i think it will call xbmc.Player().setSubtitles() way too early.

here's the relevant plugin code:
Code:
..
                player = xbmc.Player()
                for retry in range(0, 20):
                    if player.isPlaying():
                        break
                    xbmc.sleep(250)
                xbmc.Player().setSubtitles(video['SubtitlesUri'])

it basically waits 5 seconds (max.) before making the xbmc.Player().setSubtitles() call.


apart from all of that, plugins should not do this kind of silly trickery.
the sole purpose of a plugin is to provide a list of playable urls. nothing more and nothing less.
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#7
Yep you understand correct, and I fully agree with you. I'm not the developer of the plugin, and I was also a bit puzzled about why such a hack had to be done in the first place.

What would be a more correct way to pass the subtitle url for the player without such a hack? Is there a temp place where the file can be saved with a specific name in accordance with the stream url so the player automatic finds it?
Reply
#8
a plugin can provide the subtitle url to kodi by using the ListItem.setSubtitle() method.

https://codedocs.xyz/xbmc/xbmc/group__py...f8d1f07b4c
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#9
Thanks a million.

added a line further up and everything is GREAT!!!

Code:
item = xbmcgui.ListItem(path=video['Uri'], thumbnailImage=item['PrimaryImageUri'])
item.setSubtitles([video['SubtitlesUri']])

I'll contact the developer.
Reply
#10
Thanks for the solution, I'll try to update the addon as soon as possible.
Back when I implemented the addon, I think it was in the gotham-era, you couldn't set the subtitles until the player was active otherwise it didn't pick it up correctly - nice to hear that has been fixed Smile
Reply

Logout Mark Read Team Forum Stats Members Help
xbmc.Player().setSubtitles not working ?!?0